Infer

Skip to Content
API reference

API reference

Infer exposes OpenAI-compatible endpoints for both chat completions and image generation. Any SDK or HTTP client that accepts a custom base URL can call them with no code changes.

Tip:

New to Infer? Run through the Quickstart first for an API key, the base URL, and a connection test. This page assumes you already have both.

Chat completions

Endpoint

Endpoint
POST https://api-infer-pre.agentsey.ai/v1/chat/completions

Authentication

Pass your API key as a Bearer token in the Authorization header:

Authorization: Bearer your_api_key

Keys are scoped to your account. Create and rotate them in the API Keys dashboard.

Request body

FieldRequiredDescription
modelyesModel ID to route to. The examples below use gpt-5.4; see the Models catalog for all IDs.
messagesyesArray of chat messages. Must contain at least one entry.
temperaturenoSampling temperature. Defaults depend on the model.
max_tokensnoUpper bound on output tokens. On reasoning models the budget can be fully consumed by hidden reasoning tokens, which returns an empty content with finish_reason: "length".
streamnoWhen true, the response is a Server-Sent Events stream of deltas.
tools / tool_choicenoFunction calling, same schema as OpenAI.

Any other field in the OpenAI /chat/completions schema (top_p, stop, seed, response_format, …) is accepted unchanged.

Response

A non-streaming response matches the OpenAI shape:

{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "created": 1738960610,
  "model": "gpt-5.4",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "Hello! How can I help you today?" },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 13,
    "completion_tokens": 9,
    "total_tokens": 22
  }
}

Examples

curl
curl https://api-infer-pre.agentsey.ai/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "messages": [{ "role": "user", "content": "Hello" }]
  }'
python
from openai import OpenAI

client = OpenAI(
    api_key="your_api_key",
    base_url="https://api-infer-pre.agentsey.ai/v1",
)

response = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "Hello"}],
)

print(response.choices[0].message.content)
javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "your_api_key",
  baseURL: "https://api-infer-pre.agentsey.ai/v1",
});

const response = await client.chat.completions.create({
  model: "gpt-5.4",
  messages: [{ role: "user", content: "Hello" }],
});

console.log(response.choices[0].message.content);

Streaming

Set stream: true in the request body. The response becomes a Server-Sent Events stream. Each chunk follows the OpenAI chat.completion.chunk shape, and the stream terminates with a data: [DONE] line:

curl
curl https://api-infer-pre.agentsey.ai/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "stream": true,
    "messages": [{ "role": "user", "content": "Hello" }]
  }'
python
from openai import OpenAI

client = OpenAI(
    api_key="your_api_key",
    base_url="https://api-infer-pre.agentsey.ai/v1",
)

stream = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)
javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "your_api_key",
  baseURL: "https://api-infer-pre.agentsey.ai/v1",
});

const stream = await client.chat.completions.create({
  model: "gpt-5.4",
  messages: [{ role: "user", content: "Hello" }],
  stream: true,
});

for await (const chunk of stream) {
  const delta = chunk.choices[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
}

Image generation

Infer exposes synchronous image-generation surfaces and an async task API for long-running image jobs. The sync surfaces preserve upstream response shapes; the async task API stores the image result and returns URLs.

SurfaceEndpointModels
OpenAI images.generationsPOST /v1/images/generationsgpt-image-2
Gemini multimodal generateContentPOST /v1beta/models/{model}:generateContentgemini-2.5-flash-image, gemini-3-pro-image-preview, gemini-3.1-flash-image-preview
Async image tasksPOST /v1/images/generation_tasksgpt-image-2, gemini-*image*

The same API key and base URL work for both surfaces — only the request body and response shape differ.

OpenAI image generation

For gpt-image-2, send a standard OpenAI images.generations request.

Endpoint

Endpoint
POST https://api-infer-pre.agentsey.ai/v1/images/generations

Request body

FieldRequiredDescription
modelyesFixed image model ID — gpt-image-2.
promptyesNatural-language description of the image you want to generate.
nnoNumber of images to return per call. Defaults to 1.
sizenoOutput dimensions. auto (default) or <width>x<height>. See Sizes.
qualitynoQuality tier; passed through to the upstream model (e.g. low, medium, high).
output_formatnoOutput image format, e.g. png or jpeg.

gpt-image-2 sizes

gpt-image-2 accepts any resolution in size that satisfies the constraints below. Square images are typically fastest to generate.

Popular sizes:

SizeAspect
1024x1024Square
1536x1024Landscape
1024x1536Portrait
2048x20482K square
2048x11522K landscape
3840x21604K landscape
2160x38404K portrait
autoDefault

Constraints:

  • Maximum edge length must be less than or equal to 3840px.
  • Both edges must be multiples of 16px.
  • Long edge to short edge ratio must not exceed 3:1.
  • Total pixels must be at least 655,360 and no more than 8,294,400.

Examples

curl
curl -X POST "https://api-infer-pre.agentsey.ai/v1/images/generations" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
  "model": "gpt-image-2",
  "prompt": "A small clean five-point star icon, centered on a white background.",
  "n": 1,
  "size": "2048x2048",
  "quality": "low",
  "output_format": "png"
}'
python
from openai import OpenAI

client = OpenAI(
    api_key="your_api_key",
    base_url="https://api-infer-pre.agentsey.ai/v1",
)

response = client.images.generate(
    model="gpt-image-2",
    prompt="A small clean five-point star icon, centered on a white background.",
    n=1,
    size="2048x2048",
    quality="low",
    output_format="png",
)

b64_image = response.data[0].b64_json
print(b64_image[:64], "...")
javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "your_api_key",
  baseURL: "https://api-infer-pre.agentsey.ai/v1",
});

const response = await client.images.generate({
  model: "gpt-image-2",
  prompt: "A small clean five-point star icon, centered on a white background.",
  n: 1,
  size: "2048x2048",
  quality: "low",
  output_format: "png",
});

console.log(response.data[0].b64_json.slice(0, 64), "...");

Response

200 OK
{
"created": 1778471988,
"background": "opaque",
"output_format": "png",
"quality": "low",
"size": "2048x2048",
"usage": {
  "input_tokens": 20,
  "output_tokens": 397,
  "total_tokens": 417
},
"data": [
  {
    "b64_json": "<base64 image>"
  }
]
}

Save the b64_json payload to a file to view the image:

python
import base64

with open("output.png", "wb") as f:
    f.write(base64.b64decode(response.data[0].b64_json))

Gemini image generation

The Gemini image models are reachable through Google’s native generateContent route. Infer forwards this surface 1:1, so existing Google AI Studio code keeps working unchanged.

Warning:

This is not the OpenAI /v1/images/generations shape. Send a Gemini contents body and read images out of candidates[].content.parts[].inlineData.

Endpoint

Endpoint
POST https://api-infer-pre.agentsey.ai/v1beta/models/%7Bmodel%7D:generateContent

Per-model size config

Pass image-output preferences inside generationConfig.imageConfig. The supported keys differ by model:

ModelSize config
gemini-3-pro-image-previewimageConfig.imageSize controls output resolution.
gemini-3.1-flash-image-previewimageConfig.imageSize accepts 0.5K, 1K, 2K, 4K.
gemini-2.5-flash-imageimageConfig.aspectRatio only. Do not pass imageSize — output resolution follows the model’s default rule.

responseModalities must include IMAGE for the model to return an image.

Examples

gemini-3.1-flash-image-preview — request a 2K square image:

curl
curl -X POST "https://api-infer-pre.agentsey.ai/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
  "contents": [{
    "role": "user",
    "parts": [{
      "text": "Create a clean 2K square image of a red five-point star centered on a white background."
    }]
  }],
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"],
    "imageConfig": {
      "aspectRatio": "1:1",
      "imageSize": "2K"
    }
  }
}'

gemini-2.5-flash-imageaspectRatio only, no imageSize:

curl
curl -X POST "https://api-infer-pre.agentsey.ai/v1beta/models/gemini-2.5-flash-image:generateContent" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
  "contents": [{
    "role": "user",
    "parts": [{
      "text": "Create a clean square image of a red five-point star centered on a white background."
    }]
  }],
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"],
    "imageConfig": {
      "aspectRatio": "1:1"
    }
  }
}'

Response

Each generated image is delivered as base64-encoded inlineData inside a candidate:

200 OK
{
"candidates": [
  {
    "content": {
      "parts": [
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "<base64 image>"
          }
        }
      ],
      "role": "model"
    },
    "finishReason": "STOP",
    "index": 0
  }
],
"usageMetadata": {
  "promptTokenCount": 22,
  "candidatesTokenCount": 1203,
  "totalTokenCount": 1326
},
"modelVersion": "gemini-3.1-flash-image-preview",
"responseId": "response_xxx"
}

Decode the first inline image to a file:

python
import base64

part = response["candidates"][0]["content"]["parts"][0]
with open("output.jpg", "wb") as f:
    f.write(base64.b64decode(part["inlineData"]["data"]))
Tip:

Image responses are billed by token, not by pixel. The usage / usageMetadata block reports both text and image tokens — image tokens dominate the bill on the Gemini preview models.

Async image tasks

Use async image tasks when the client should create a job, poll status, and receive stored image URLs after completion.

Create a task

Endpoint
POST https://api-infer-pre.agentsey.ai/v1/images/generation_tasks

Request body

FieldRequiredDescription
modelyesImage model ID. See Supported async models.
promptyesNatural-language description of the image.
nnoNumber of images to generate. The server caps this value.
sizenoOpenAI-style size such as 1024x1024. Used by gpt-image-2; Gemini ignores it.
qualitynoQuality tier, such as low, medium, high, or provider-specific values.
output_formatnopng, jpeg, jpg, or webp. Used by gpt-image-2; Gemini storage follows the returned image type when detectable.
response_formatnoIf provided, must be url. Async tasks always return stored URLs.
usernoOpenAI end-user identifier, forwarded for abuse monitoring and end-user budgets.

Parameter support by model

The request accepts one flat parameter set, but each model honors only a subset. Unsupported parameters are accepted and silently ignored — they never error.

Parametergpt-image-2Gemini
model, promptrequiredrequired
user
nmodel-decided
size
quality, style, background, moderation, output_compression
output_formatstorage fallback

Legend: ✓ applied · ✗ accepted but ignored · model-decided the model controls the count · storage fallback is used only when the returned image type cannot be detected.

Warning:

Async Gemini tasks ignore size — the model decides the output. To control Gemini output resolution, use the sync generateContent route’s generationConfig.imageConfig instead; that key does not apply to async tasks.

Supported async models

  • gpt-image-2
  • gemini-2.5-flash-image
  • gemini-3-pro-image-preview
  • gemini-3.1-flash-image-preview

Deployments may narrow or extend this list.

Create example

curl
curl -X POST "https://api-infer-pre.agentsey.ai/v1/images/generation_tasks" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
  "model": "gpt-image-2",
  "prompt": "A small clean five-point star icon, centered on a white background.",
  "n": 1,
  "size": "1024x1024",
  "quality": "low",
  "output_format": "png",
  "response_format": "url"
}'

Create response

200 OK
{
"id": "imgtask_...",
"object": "image.generation_task",
"created": 1780501937,
"task_id": "imgtask_...",
"status": "queued",
"model": "gpt-image-2",
"created_at": "2026-06-11T12:00:00+00:00"
}

Poll a task

Poll the created task with GET /v1/images/generation_tasks/{task_id}.

Endpoint
GET https://api-infer-pre.agentsey.ai/v1/images/generation_tasks/{task_id}
curl
curl "https://api-infer-pre.agentsey.ai/v1/images/generation_tasks/imgtask_..." \
-H "Authorization: Bearer your_api_key"

status is one of queued, in_progress, completed, or failed. A completed task returns OpenAI-style data items with stored image URLs:

completed
{
"id": "imgtask_...",
"object": "image.generation_task",
"created": 1780501937,
"task_id": "imgtask_...",
"status": "completed",
"model": "gpt-image-2",
"created_at": "2026-06-11T12:00:00+00:00",
"data": [
  {
    "url": "https://..."
  }
],
"usage": {
  "input_tokens": 20,
  "output_tokens": 397,
  "total_tokens": 417
}
}

Failed tasks return an error object. Listing all image tasks is not supported.

Error codes

CodeMeaningFix
400Invalid request (unknown model, malformed body, unsupported parameter)Verify the model ID matches the Models page (IDs are case-sensitive) and check the request body against the field table above.
401Invalid or missing API keyCheck that your key is set correctly and has not been revoked in the dashboard.
402Insufficient creditsTop up on the Credits page, then retry.
429Rate limitedBack off and retry with exponential delay. Consider spreading load across models.
500Server errorRetry the request. If it persists, try a different model or contact support.

See also

Last updated on