Example: cURL image generation
curl https://api.cheaperinference.com/v1/images/generations \
-H "Authorization: Bearer ir_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "nano-banana-pro",
"prompt": "A clean product render of a banana invoice",
"n": 1,
"size": "1024x1024",
"resolution": "1K",
"quality": "high",
"response_format": "url"
}'
Use /v1/images/generations for every model whose
/v1/models entry has type: "image" or
capabilities.image_generation: true, including
grok-imagine. Image-generation models are not accepted by
/v1/responses, /v1/chat/completions, or
/v1/completions.
Example: Grok Imagine
curl https://api.cheaperinference.com/v1/images/generations \
-H "Authorization: Bearer ir_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine",
"prompt": "A cinematic city at night",
"n": 1,
"response_format": "url"
}'
Vision input
Vision-capable chat models accept OpenAI image_url content parts
and Anthropic-style base64 image blocks. Use up to 10 images, 5MB per image,
and 23MB total decoded base64 image data. The complete serialized JSON body
must be 31MiB or smaller. Split larger workloads across requests; public image
URLs reduce body size but do not change the 10-image limit. Models with this
capability are marked Vision input in the model list.
Prompt caching
cache_control is passed through when supported by the selected
model. Cache reads and writes use the provider-specific cache rates when they
are available. If no cache-read rate is reported, reads fall back to 10% of the
normal input rate; cache writes without a separate rate use the normal input rate.
Kimi K3 reasoning effort
Send reasoning: {"effort": "low"},
"high", or "max" with
model: "kimi-k3". Kimi K3 does not expose
medium as a native effort level. Set the value explicitly when
consistent behavior matters; reasoning tokens are billed as output usage.
Temporary vision uploads
For larger base64 payloads, upload each image separately as multipart form data.
The returned file ID expires after one hour and is converted to a short-lived,
private image URL when the chat request is forwarded. Uploads keep the JSON body
small but do not change the limit of 10 images per request.
curl https://api.cheaperinference.com/v1/uploads \
-H "Authorization: Bearer ir_live_YOUR_API_KEY" \
-F "file=@tile.png"
# Use the returned id in a chat message:
{
"type": "image_file",
"image_file": {"file_id": "img_RETURNED_ID"}
}
# Optional early deletion:
curl -X DELETE https://api.cheaperinference.com/v1/uploads/img_RETURNED_ID \
-H "Authorization: Bearer ir_live_YOUR_API_KEY"
Example: JavaScript SDK
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "ir_live_YOUR_API_KEY",
baseURL: "https://api.cheaperinference.com/v1"
});
const response = await client.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "Hello! Who are you?" }]
});
Example: Python SDK
from openai import OpenAI
client = OpenAI(
api_key="ir_live_YOUR_API_KEY",
base_url="https://api.cheaperinference.com/v1",
)
response = client.chat.completions.create(
model="claude-opus-4.6",
messages=[{"role": "user", "content": "Hello! Who are you?"}],
)
List models
curl https://api.cheaperinference.com/v1/models \
-H "Authorization: Bearer ir_live_YOUR_API_KEY"
Streaming
Models marked Streaming accept "stream": true on
/v1/responses, /v1/chat/completions, and
/v1/completions. Streams use server-sent events, and wallet usage is
settled when the stream completes. The
gateway can change routes before output starts; after the first event is sent, an
interrupted stream must be retried as a complete request.
Available model names and pricing
Copy an exact model id into the model field. Text-model prices are per 1M
tokens. When a model shows an input-token cutoff, the entire request uses the rate for
its input-token tier. Image models show either separate token rates for input, text,
thinking, and image output or a fixed price per generated image.
Model catalog API
Retrieve currently available models and their current catalog rates. A fallback
route can change the final rate, but never above the applicable direct list price.
Filter by type, vision, reasoning, streaming, or
provider to compare only models that meet your workload's requirements.
curl 'https://api.cheaperinference.com/v1/models?type=text&vision=true&streaming=true' \
-H 'Authorization: Bearer ir_live_YOUR_API_KEY'
Token rates are USD per 1 million tokens. Fixed media rates use
media_input_unit_price and media_unit_price per unit. For
tiered models, use pricing.above_threshold when the request exceeds
input_token_price_threshold.
Automatic retries and fallback
Network failures and HTTP 404, 408, 409, 425, 429, and 5xx responses are retried
once. Other 4xx responses are not retried; when another route is eligible, the
gateway immediately tries it in price order.
The serving route determines the settled rate, capped at direct list price with no
separate Cheaper Inference routing surcharge.
Cheaper Inference does not store prompt or response bodies in its application
database; billing and operational metadata is retained for History and support.
Billing and wallet
- Wallet balance is checked before a request starts.
- Image requests use the displayed token rates unless the model shows a fixed per-image price.
- Add funds manually or enable auto-recharge from the dashboard.
Common errors
401 Invalid or missing API key.
403 The API key does not allow this model or client IP.
402 Insufficient wallet balance.
400 Unsupported model or invalid request body.
413 Request body or base64 vision payload exceeds the documented limits.
429 Request was rate limited; retry with backoff.
502 Provider or transport failure after eligible routes were exhausted.
503 No eligible provider route is currently available.
FAQ
- Do I need a contract? No. Create an account, add funds, and start sending requests.
- Do I need to migrate code? Usually only the API key and base URL change.
- Where do I pick the model? Pass the model id in every request.
- Can I track savings? Yes. History shows request count, tokens, cost, and estimated savings.
Successful response
{
"output": [{
"role": "assistant",
"content": [{"type": "output_text", "text": "Hello!"}]
}],
"usage": {
"input_tokens": 12,
"output_tokens": 3,
"total_tokens": 15
}
}
Security and keys
- Store API keys in environment variables, not frontend code.
- Create separate keys for production, staging, and local testing.
- Configure model, IP, expiration, rate, concurrency, daily quota, and monthly budget controls from API Keys.
- If a key is exposed, delete it and create a new one.
- Use History to audit request volume, token usage, and spend.
Support
Use the Contact tab for billing, API, or account questions. We typically
answer in under 12h. For platform availability, check the Status link in the footer.