API Documentation

OpenAI-compatible. Change two lines and access 100+ models — GPT, Claude, DeepSeek, Qwen, and more.

Base URL: https://api.aimodelapi.ai/v1Auth: Bearer sk-ama-...Regional: sg · jp · hk · th · us · eu

Quick Start

ModelAPI is fully OpenAI-compatible. Two config lines unlock 50+ frontier models with transparent pricing.

01
Get your API key
Register → Dashboard → API Keys. Format: sk-ama-xxxxxx — usually under a minute.
02
Set the base URL
Point your OpenAI SDK at api.aimodelapi.ai/v1 — everything else stays the same.
03
50+ models, one key
GPT-5.5, Claude Opus 4.7, DeepSeek V4, Gemini 3.1 — switch models by changing one string.
typescript
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.

python
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.

bash
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.

typescript
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

NEW

The 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.

python
# 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.

typescript
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-flash

Model Groups

NEW

Prefer 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.

typescript
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)

NEW

Bundle up to 1,000 calls per job — priced at half the interactive rate — ideal for enrichment, QA, or bulk labelling workloads.

typescript
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

NEW

Plug in Anthropic/OpenAI/Google keys directly. Routing is $0.50/M consolidated — perfect when list prices are steep.

typescript
// 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.

MethodEndpointDescriptionAuth
POST/v1/chat/completionsCreate chat completion (streaming + sync)API Key
POST/v1/batchSubmit async batch job (50% tier)API Key
GET/v1/batch/:idFetch batch status + payloadsAPI Key
GET/v1/batchList batchesAPI Key
GET/v1/modelsList models + aliasesAPI Key
GET/v1/models/:idModel metadata + metered pricingAPI Key
POST/auth/registerCreate accountNone
POST/auth/loginSign in → JWT cookie/bodyNone
GET/v1/keysList API keys (dashboard scope)JWT
POST/v1/keysProvision key (+ optional BYOK)JWT
DELETE/v1/keys/:idRevoke key immediatelyJWT
GET/v1/creditsWallet balance & ledgerJWT
POST/v1/credits/topupStart Stripe/WeChat/Alipay/USDT flowsJWT
GET/v1/usageUsage rollups per day/modelJWT