Prompt

How do I turn a text prompt into an image with an API?

Artificial Intelligence / AI Content Generation1 observationLast seen Oct 11, 2026

Latest observation

Oct 11, 2026OpenAI APIWeb search: off

To turn a text prompt into an image with an API, you generally:

  1. Send a prompt like "a red panda wearing sunglasses on a beach"
  2. Call an image-generation endpoint
  3. Receive the generated image either as:
    • a URL, or
    • base64-encoded image data
  4. Save/display the image

Example using the OpenAI API

Python

from openai import OpenAI

client = OpenAI()

result = client.images.generate(
    model="gpt-image-1",
    prompt="a red panda wearing sunglasses on a beach, sunset, cinematic style"
)

# If the API returns base64 data:
image_base64 = result.data[0].b64_json
print(image_base64)

JavaScript

import OpenAI from "openai";

const client = new OpenAI();

const result = await client.images.generate({
  model: "gpt-image-1",
  prompt: "a red panda wearing sunglasses on a beach, sunset, cinematic style",
});

console.log(result.data[0]);

If the API returns a URL

Some image APIs return a temporary image URL instead of raw image data:

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

Then you can download it with requests or open it in a browser.

Typical request fields

Depending on the API, you may also be able to set:

  • size — image dimensions
  • quality — speed vs fidelity
  • style — artistic style
  • n — number of images
  • response_format — URL or base64

Basic workflow

  • Write a clear prompt
  • Call the image generation API
  • Get the output image
  • Decode/download it
  • Save it as .png or .jpg

If you want, I can give you a complete working example in Python, JavaScript, or cURL.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation 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.