API Documentation
OpenAI-compatible. Change two lines and access 100+ models — GPT, Claude, DeepSeek, Qwen, and more.
https://api.aimodelapi.ai/v1Auth: Bearer sk-ama-...Regional: sg · jp · hk · th · us · euQuick Start
ModelAPI is fully OpenAI-compatible. Two config lines unlock 50+ frontier models with transparent pricing.
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-ama-YOUR_KEY', // 1. Dashboard → API Keys
baseURL: 'https://api.aimodelapi.ai/v1', // 2. Only change needed here
});
// Access any routed model:
const res = await client.chat.completions.create({
model: 'claude-opus-4-7', // e.g. gpt-5.5, deepseek-v4-flash, gemini-3.1-pro
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(res.choices[0].message.content);Python
Use the official OpenAI Python package — no extra dependencies.
from openai import OpenAI
client = OpenAI(
api_key="sk-ama-YOUR_KEY",
base_url="https://api.aimodelapi.ai/v1"
)
response = client.chat.completions.create(
model="claude-sonnet-4",
messages=[{"role": "user", "content": "Explain transformers"}]
)
print(response.choices[0].message.content)cURL
Raw HTTP works from any stack or toolchain.
curl https://api.aimodelapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-ama-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.0-flash",
"messages": [{"role": "user", "content": "What is 2+2?"}],
"max_tokens": 100
}'Streaming
All models support Server-Sent Events. Set stream: true.
const stream = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Write a haiku about AI' }],
stream: true,
});
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta?.content ?? '';
process.stdout.write(delta);
}Global Endpoints
NEWThe primary hostname auto-routes to the nearest PoP. Pick a regional host when you need a fixed geography, failover, or compliance — same keys, models, and API.
# Primary — auto-selects nearest node (recommended)
BASE_URL = "https://api.aimodelapi.ai/v1"
# Regional — same OpenAI-compatible paths
BASE_URL = "https://sg.api.aimodelapi.ai/v1" # Singapore
BASE_URL = "https://jp.api.aimodelapi.ai/v1" # Tokyo
BASE_URL = "https://hk.api.aimodelapi.ai/v1" # Hong Kong / China egress
BASE_URL = "https://th.api.aimodelapi.ai/v1" # Bangkok
BASE_URL = "https://us.api.aimodelapi.ai/v1" # US East (Virginia)
BASE_URL = "https://eu.api.aimodelapi.ai/v1" # Frankfurt
from openai import OpenAI
client = OpenAI(api_key="sk-ama-YOUR_KEY", base_url=BASE_URL)Auto Routing
Use model: "auto" to let ModelAPI pick the cheapest model that can fulfil the request.
const res = await client.chat.completions.create({
model: 'auto',
messages: [{ role: 'user', content: 'Summarize this text in one sentence...' }],
});
console.log(res.model); // e.g. glm-5-flash or gemini-2.0-flashModel Groups
NEWPrefer a smart alias (ama/smart-*) instead of hard-coding IDs: complex traffic goes to frontier models and routine tasks to cheapest tiers, with automatic failover.
const SMART_MODELS = {
'ama/smart-code': 'Coding: frontier when needed, value tier for bulk edits',
'ama/smart-write': 'Marketing & editorial copy',
'ama/smart-reason': 'Long reasoning traces',
'ama/smart-analyze': 'Structured analysis & summaries',
};
const res = await client.chat.completions.create({
model: 'ama/smart-code',
messages: [{ role: 'user', content: 'Refactor for O(n) complexity...' }],
});
console.log(`Used model: ${res.model}`);Batch API (50% off)
NEWBundle up to 1,000 calls per job — priced at half the interactive rate — ideal for enrichment, QA, or bulk labelling workloads.
const batchRes = await fetch('https://api.aimodelapi.ai/v1/batch', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk-ama-YOUR_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
tier: 'batch_50',
requests: [
{ custom_id: 'doc_1', model: 'deepseek-r1', messages: [{ role: 'user', content: 'Summarize...' }] },
],
callback_url: 'https://yourapp.com/webhooks/batch',
}),
});
const { poll_url } = await batchRes.json();
const result = await fetch(`https://api.aimodelapi.ai${poll_url}`, {
headers: { 'Authorization': 'Bearer sk-ama-YOUR_KEY' },
});BYOK Setup
NEWPlug in Anthropic/OpenAI/Google keys directly. Routing is $0.50/M consolidated — perfect when list prices are steep.
// Dashboard → API Keys → BYOK tab registers your upstream keys.
// Standard credits: tuned for <$3/M workloads.
// BYOK: flatten routing to ~$0.50/M regardless of upstream list price.
const res = await client.chat.completions.create({
model: 'claude-opus-4-7',
messages: [{ role: 'user', content: 'Complex analysis...' }],
});API Reference
All endpoints under https://api.aimodelapi.ai. Gateway endpoints require an API Key; account endpoints require a JWT from /auth/login.
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /v1/chat/completions | Create chat completion (streaming + sync) | API Key |
| POST | /v1/batch | Submit async batch job (50% tier) | API Key |
| GET | /v1/batch/:id | Fetch batch status + payloads | API Key |
| GET | /v1/batch | List batches | API Key |
| GET | /v1/models | List models + aliases | API Key |
| GET | /v1/models/:id | Model metadata + metered pricing | API Key |
| POST | /auth/register | Create account | None |
| POST | /auth/login | Sign in → JWT cookie/body | None |
| GET | /v1/keys | List API keys (dashboard scope) | JWT |
| POST | /v1/keys | Provision key (+ optional BYOK) | JWT |
| DELETE | /v1/keys/:id | Revoke key immediately | JWT |
| GET | /v1/credits | Wallet balance & ledger | JWT |
| POST | /v1/credits/topup | Start Stripe/WeChat/Alipay/USDT flows | JWT |
| GET | /v1/usage | Usage rollups per day/model | JWT |