Image Generation
Generate images from text prompts using the Token101 Images API.
Overview
Token101 exposes an OpenAI Images-compatible API (/api/v1/images/generations). The route is available for OpenAI SDKs and raw HTTP clients, while live model availability is controlled by the model catalog. If an image model is temporarily paused, the request returns model_not_enabled instead of charging credits.
Endpoint
POST https://token.ppthub.shop/api/v1/images/generationsAuthentication
Include your Token101 API key in the Authorization header:
Authorization: Bearer sk-your-token101-api-keyQuick Example
curl
curl https://token.ppthub.shop/api/v1/images/generations \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $TOKEN101_API_KEY" \
--data '{
"model": "gpt-image-1",
"prompt": "A watercolor painting of a mountain lake at sunset",
"n": 1,
"size": "1024x1024"
}'Python (OpenAI SDK)
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKEN101_API_KEY"],
base_url="https://token.ppthub.shop/api/v1",
)
response = client.images.generate(
model="gpt-image-1",
prompt="A watercolor painting of a mountain lake at sunset",
n=1,
size="1024x1024",
)
image = response.data[0]
# Depending on the model, either `url` or `b64_json` is populated — check which one.
print(image.url or image.b64_json)Node.js / TypeScript (OpenAI SDK)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.TOKEN101_API_KEY!,
baseURL: 'https://token.ppthub.shop/api/v1',
});
const response = await client.images.generate({
model: 'gpt-image-1',
prompt: 'A watercolor painting of a mountain lake at sunset',
n: 1,
size: '1024x1024',
});
// Depending on the model, either `url` or `b64_json` is populated — check which one.
console.log(response.data[0]?.url ?? response.data[0]?.b64_json);Request Fields
| Field | Type | Description |
|---|---|---|
model | string | Required. Image-capable model ID. Check Supported Models or GET /api/v1/public/models before dispatching. |
prompt | string | Required. Text description of the desired image |
n | integer | Optional. Number of images to generate (1–10, default: 1) |
size | string | Optional. One of auto, 1024x1024, 1024x1536, 1536x1024 |
quality | string | Optional. One of auto, low, medium, high |
response_format | string | Optional. url or b64_json. Depending on the model, the response may only contain b64_json data — inspect the actual response shape rather than assuming a url is present. |
style | string | Optional. Common values include vivid and natural |
Response Format
A successful response returns a JSON object with the generated image data:
{
"created": 1715659876,
"data": [
{
"url": "https://..."
}
]
}When response_format is b64_json, the data array contains b64_json fields instead of URLs:
{
"created": 1715659876,
"data": [
{
"b64_json": "..."
}
]
}Model Availability
The image route and image models are managed separately. The route may be healthy even when a specific image model is paused for upstream stability. Use GET /api/v1/public/models and check each model's outputModalities and operationalStatus before enabling it in your client.
When a model is paused, Token101 returns an API error with reason: "model_not_enabled". That means the request format and API key were accepted, but live routing for that model is currently disabled. No successful image charge should be created for that failed request.
Image generation is priced per image, not per token. See Billing & Credits for current pricing and the control panel for the latest status.
Pricing
Image generation uses per-image pricing instead of per-token billing:
| Item | Pricing behavior |
|---|---|
| Image generation | Charged per successfully generated image |
The cost is deducted from your credits when the image is generated. Exact unit price, size/quality support, and model availability are shown in the live model catalog and billing pages.
Limitations
- Non-streaming: Image generation does not support streaming. Requests block until the image is ready (typically 10–30 seconds).
- Model support: Image-capable models can be temporarily paused. Check
operationalStatusbefore sending production traffic. - Content policy: Prompts that violate OpenAI's content policy will be rejected by the upstream provider.
- Rate limits: Image generation counts against your standard RPM limit but uses a separate concurrency budget due to longer processing times.
Troubleshooting
401 Unauthorized
Check your API key. See Authentication for details.
400 Invalid model or model_not_enabled
Confirm that the model exists and is currently enabled in GET /api/v1/public/models. model_not_enabled means the image route is reachable but live routing for that model is paused.
429 Too Many Requests
You've hit the rate limit. Image generation requests take longer than text requests, so concurrent limits may be reached sooner. See Rate Limits.
Image generation takes a long time
Image generation typically takes 10–30 seconds. This is normal. If requests consistently time out, try reducing n to 1 or using a smaller size.
Next Steps
- Supported Models — full list of text and image models
- Billing & Credits — understand how image generation is billed
- API Reference — full endpoint documentation