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.
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
POST https://api-infer-pre.agentsey.ai/v1/chat/completionsAuthentication
Pass your API key as a Bearer token in the Authorization header:
Authorization: Bearer your_api_keyKeys are scoped to your account. Create and rotate them in the API Keys dashboard.
Request body
| Field | Required | Description |
|---|---|---|
model | yes | Model ID to route to. The examples below use gpt-5.4; see the Models catalog for all IDs. |
messages | yes | Array of chat messages. Must contain at least one entry. |
temperature | no | Sampling temperature. Defaults depend on the model. |
max_tokens | no | Upper 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". |
stream | no | When true, the response is a Server-Sent Events stream of deltas. |
tools / tool_choice | no | Function 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 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" }]
}'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)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 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" }]
}'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)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.
| Surface | Endpoint | Models |
|---|---|---|
OpenAI images.generations | POST /v1/images/generations | gpt-image-2 |
Gemini multimodal generateContent | POST /v1beta/models/{model}:generateContent | gemini-2.5-flash-image, gemini-3-pro-image-preview, gemini-3.1-flash-image-preview |
| Async image tasks | POST /v1/images/generation_tasks | gpt-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
POST https://api-infer-pre.agentsey.ai/v1/images/generationsRequest body
| Field | Required | Description |
|---|---|---|
model | yes | Fixed image model ID — gpt-image-2. |
prompt | yes | Natural-language description of the image you want to generate. |
n | no | Number of images to return per call. Defaults to 1. |
size | no | Output dimensions. auto (default) or <width>x<height>. See Sizes. |
quality | no | Quality tier; passed through to the upstream model (e.g. low, medium, high). |
output_format | no | Output 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:
| Size | Aspect |
|---|---|
1024x1024 | Square |
1536x1024 | Landscape |
1024x1536 | Portrait |
2048x2048 | 2K square |
2048x1152 | 2K landscape |
3840x2160 | 4K landscape |
2160x3840 | 4K portrait |
auto | Default |
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,360and no more than8,294,400.
Examples
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"
}'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], "...")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
{
"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:
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.
This is not the OpenAI /v1/images/generations shape. Send a Gemini
contents body and read images out of
candidates[].content.parts[].inlineData.
Endpoint
POST https://api-infer-pre.agentsey.ai/v1beta/models/%7Bmodel%7D:generateContentPer-model size config
Pass image-output preferences inside generationConfig.imageConfig. The supported keys differ by model:
| Model | Size config |
|---|---|
gemini-3-pro-image-preview | imageConfig.imageSize controls output resolution. |
gemini-3.1-flash-image-preview | imageConfig.imageSize accepts 0.5K, 1K, 2K, 4K. |
gemini-2.5-flash-image | imageConfig.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 -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-image — aspectRatio only, no imageSize:
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:
{
"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:
import base64
part = response["candidates"][0]["content"]["parts"][0]
with open("output.jpg", "wb") as f:
f.write(base64.b64decode(part["inlineData"]["data"]))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
POST https://api-infer-pre.agentsey.ai/v1/images/generation_tasksRequest body
| Field | Required | Description |
|---|---|---|
model | yes | Image model ID. See Supported async models. |
prompt | yes | Natural-language description of the image. |
n | no | Number of images to generate. The server caps this value. |
size | no | OpenAI-style size such as 1024x1024. Used by gpt-image-2; Gemini ignores it. |
quality | no | Quality tier, such as low, medium, high, or provider-specific values. |
output_format | no | png, jpeg, jpg, or webp. Used by gpt-image-2; Gemini storage follows the returned image type when detectable. |
response_format | no | If provided, must be url. Async tasks always return stored URLs. |
user | no | OpenAI 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.
| Parameter | gpt-image-2 | Gemini |
|---|---|---|
model, prompt | required | required |
user | ✓ | ✓ |
n | ✓ | model-decided |
size | ✓ | ✗ |
quality, style, background, moderation, output_compression | ✓ | ✗ |
output_format | ✓ | storage 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.
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-2gemini-2.5-flash-imagegemini-3-pro-image-previewgemini-3.1-flash-image-preview
Deployments may narrow or extend this list.
Create example
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
{
"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}.
GET https://api-infer-pre.agentsey.ai/v1/images/generation_tasks/{task_id}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:
{
"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
See also
- OpenAI Chat Completions reference : Infer mirrors this schema.
- OpenAI images reference : Infer mirrors this schema for image generation.
- Gemini image generation guide : upstream Google docs for the native
generateContentflow. - Models: full catalog with live pricing.
- Quickstart: API key, base URL, and first call.