Skip to content

GPT Image API Examples

Using the official OpenAI SDK to call gpt-image models.

Basic Configuration

Before starting to use the API, please ensure you have obtained an API Key. If not, please refer to Create API Key.

Basic Information

  • API Base Generations URL: https://api.agentsflare.com/openai/v1/images/generations
  • API Base Edits URL: https://api.agentsflare.com/openai/v1/images/edits
  • Authentication Method: Bearer Token
  • Content Type: application/json

Request Examples

bash
curl https://api.agentsflare.com/openai/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-image-1.5",
    "prompt": "A cute baby sea otter",
    "n": 1,
    "size": "1024x1024"
  }'
python
import base64
from openai import OpenAI

url = "https://api.agentsflare.com/openai/v1"

client = OpenAI(
    base_url=url,
    api_key="YOUR_API_KEY"
)

img = client.images.generate(
    model="gpt-image-1.5",
    prompt="A cute baby sea otter",
    n=1,
    size="1024x1024"
)

print(img.data[0].url)
javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.AGENTSFLARE_API_KEY,
  baseURL: "https://api.agentsflare.com/openai/v1"
});

async function main() {
  const image = await client.images.generate({
    model: "gpt-image-1.5",
    prompt: "A cute baby sea otter",
    n: 1,
    size: "1024x1024"
  });

  console.log(image.data[0].url);
}

main();
java
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.images.ImageGenerateParams;

public class Main {
  public static void main(String[] args) {
    String apiKey = System.getenv("AGENTSFLARE_API_KEY");
    if (apiKey == null || apiKey.isBlank()) {
      throw new IllegalStateException("Missing AGENTSFLARE_API_KEY env var");
    }

    OpenAIClient client = OpenAIOkHttpClient.builder()
        .apiKey(apiKey)
        .baseUrl("https://api.agentsflare.com/openai/v1")
        .build();

    ImageGenerateParams params = ImageGenerateParams.builder()
        .model("gpt-image-1.5")
        .prompt("A cute baby sea otter")
        .n(1)
        .size(ImageGenerateParams.Size._1024X1024)
        .build();

    var res = client.images().generate(params);

    System.out.println(res.data().get(0).url());
  }
}
go
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	openai "github.com/openai/openai-go"
	"github.com/openai/openai-go/option"
)

func main() {
	apiKey := os.Getenv("AGENTSFLARE_API_KEY")
	if apiKey == "" {
		log.Fatal("missing env AGENTSFLARE_API_KEY")
	}

	client := openai.NewClient(
		option.WithAPIKey(apiKey),
		option.WithBaseURL("https://api.agentsflare.com/openai/v1"),
	)

	ctx := context.Background()

	image, err := client.Images.Generate(ctx, openai.ImageGenerateParams{
		Model:  openai.F(openai.ImageModelDallE3),
		Prompt: openai.F("A cute baby sea otter"),
		N:      openai.F(int64(1)),
		Size:   openai.F(openai.ImageGenerateParamsSize1024x1024),
	})
	if err != nil {
		log.Fatalf("image generation failed: %v", err)
	}

	fmt.Println(image.Data[0].URL)
}
javascript
const { OpenAI } = require("openai");

const client = new OpenAI({
  apiKey: process.env.AGENTSFLARE_API_KEY,
  baseURL: "https://api.agentsflare.com/openai/v1"
});

async function main() {
  const image = await client.images.generate({
    model: "gpt-image-1.5",
    prompt: "A cute baby sea otter",
    n: 1,
    size: "1024x1024"
  });

  console.log(image.data[0].url);
}

main();

Response Example

{
  "created": 1589478378,
  "data": [
    {
      "url": "https://..."
    }
  ]
}

Request Parameters

For detailed parameters, see Images API

This documentation is licensed under CC BY-SA 4.0.