Prompt

How do I generate images from text with an API?

Artificial Intelligence / AI Content Generation2 observationsLast seen Oct 18, 2026

Latest observation

Oct 18, 2026OpenAI APIWeb search: off

You can generate images from text with an image-generation API by sending a prompt (the text description) to the model and receiving back an image URL or image bytes.

Basic flow

  1. Choose an image model/provider
    • Examples: OpenAI, Stability AI, Adobe, Replicate, etc.
  2. Create an API key
    • Store it securely in an environment variable.
  3. Send a text prompt
    • Example: “A futuristic city at sunset, cinematic lighting, ultra-detailed”
  4. Get the result
    • Usually returned as:
      • a hosted image URL
      • base64-encoded image data
      • a file you can save locally
  5. Display or store the image

Example with OpenAI-style API

Python

from openai import OpenAI

client = OpenAI(api_key="YOUR_API_KEY")

response = client.images.generate(
    model="gpt-image-1",
    prompt="A red fox wearing a spacesuit on Mars, realistic, high detail"
)

image_url = response.data[0].url
print(image_url)

JavaScript

import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

const response = await client.images.generate({
  model: "gpt-image-1",
  prompt: "A red fox wearing a spacesuit on Mars, realistic, high detail"
});

console.log(response.data[0].url);

Common options

Depending on the API, you may also pass:

  • size — image dimensions like 1024x1024
  • style — realistic, artistic, etc.
  • n — number of images to generate
  • negative_prompt — what to avoid
  • seed — for repeatability
  • quality — speed vs detail

Practical tips

  • Be specific: subject, style, lighting, composition, mood.
  • Add constraints: “no text,” “white background,” “centered composition.”
  • Iterate by refining the prompt.
  • Check the provider’s content policy and rate limits.

If you want the simplest possible implementation

Tell me:

  • your language: Python / JavaScript / cURL / another
  • which provider you want to use

…and I’ll give you a copy-paste example.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.