Skip Navigation
Show nav
Heroku Dev Center Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
Heroku Dev Center Dev Center
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log in or Sign up
View categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Buildpacks
    • Platform Principles
  • Developer Tools
    • AI Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Working with Node.js
      • Node.js Behavior in Heroku
      • Troubleshooting Node.js Apps
    • Ruby
      • Rails Support
        • Working with Rails
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • Working with PHP
      • PHP Behavior in Heroku
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Inference Essentials
    • Inference API
    • Inference Quick Start Guides
    • AI Models
    • Tool Use
    • AI Integrations
    • Vector Database
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
    • Heroku AppLink
      • Working with Heroku AppLink
      • Heroku AppLink Reference
      • Getting Started with Heroku AppLink
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Other Salesforce Integrations
  • AI
  • Inference Quick Start Guides
  • JavaScript (Node.js) Quick Start Guide for /v1/images/generations API

JavaScript (Node.js) Quick Start Guide for /v1/images/generations API

English — 日本語に切り替える

Table of Contents [expand]

  • Prerequisites
  • JavaScript Example Code

Last updated February 09, 2026

The Stability AI Stable Image Ultra (stability-image-ultra) model allows you to generate high-quality, detailed images from descriptive text prompts. This guide details how to access the v1-images-generations API using JavaScript.

Prerequisites

Before making requests, provision access to the model of your choice.

  1. Attach an inference addon to an app of yours:

    # If you don't have an app yet, you can create one with:
    heroku create $APP_NAME # specify the name you want for your app (or skip this step to use an existing app you have)
    
    # Create and attach one of our chat models to your app, $APP_NAME:
    heroku addons:create heroku-inference:standard -a $APP_NAME --as INFERENCE
    
  2. Install the necessary axios package:

    npm install axios
    

JavaScript Example Code

const axios = require('axios');
const fs = require('fs');
const { exec } = require('child_process');

// Assert that environment variables are set
const DIFFUSION_URL = process.env.DIFFUSION_URL;
const DIFFUSION_KEY = process.env.DIFFUSION_KEY;

if (!DIFFUSION_URL || !DIFFUSION_KEY) {
    console.error("Missing required environment variables.");
    console.log("Set them up using the following commands:");
    console.log("export DIFFUSION_URL=$(heroku config:get -a $APP_NAME DIFFUSION_URL)");
    console.log("export DIFFUSION_KEY=$(heroku config:get -a $APP_NAME DIFFUSION_KEY)");
    process.exit(1);
}

async function parseImageOutput(response, payload, filename = null) {
    if (response.status === 200) {
        if (payload.response_format === "base64") {
            filename = filename || `${payload.prompt.slice(0, 20).replace(/ /g, "_").toLowerCase()}.png`;
            fs.writeFileSync(filename, response.data.data[0].b64_json, 'base64');
            console.log(`Image saved as ${filename}`);

            // Automatically open the image after saving
            openImage(filename);
        } else {
            console.log("Download the image from:", response.data.data[0].url);
        }
    } else {
        console.log(`Request failed: ${response.status}, ${response.statusText}`);
    }
}

function openImage(filename) {
    const platform = process.platform;
    let command;

    if (platform === 'darwin') { // macOS
        command = `open ${filename}`;
    } else if (platform === 'win32') { // Windows
        command = `start ${filename}`;
    } else if (platform === 'linux') { // Linux
        command = `xdg-open ${filename}`;
    }

    if (command) {
        exec(command, (error) => {
            if (error) {
                console.error(`Failed to open image: ${error.message}`);
            } else {
                console.log(`Opened image: ${filename}`);
            }
        });
    } else {
        console.log("Automatic image opening is not supported on this platform.");
    }
}

async function generateImage(payload, filename = null) {
    try {
        const response = await axios.post(`${DIFFUSION_URL}/v1/images/generations`, payload, {
            headers: {
                'Authorization': `Bearer ${DIFFUSION_KEY}`,
                'Content-Type': 'application/json'
            }
        });
        await parseImageOutput(response, payload, filename);
    } catch (error) {
        console.error("Error generating image:", error.message);
    }
}

// Example payload
const payload = {
    model: "stable-image-ultra",
    prompt: "A surreal landscape with glowing mushrooms under a night sky.",
    aspect_ratio: "16:9",
    output_format: "png",
    seed: 123,
    negative_prompt: "crowded, noisy, chaotic"
};

// Generate image
generateImage(payload);

Feedback

Log in to submit feedback.

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2026 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices