• Home
  • Search
  • AI Services
  • Models
  • Writing
  • Multimedia Creation
  • Translation & Others
Home›Developer Center›OpenRouter API

OpenRouter API

API DocumentationAPI Quick StartOpenAI ChatGPT APIAnthropic (Claude) APIGoogle Gemini APIGoogle Search APIGoogle News APIOpenRouter APIAPI Pricing
CLI & Agent Guidescc-switch macOScc-switch Windowscc-switch LinuxOpenCode macOSOpenCode WindowsOpenCode LinuxOpenClaw macOSOpenClaw WindowsOpenClaw LinuxHermes Agent macOSHermes Agent WindowsHermes Agent LinuxClaude Code CLI macOSClaude Code CLI WindowsClaude Code CLI LinuxCodex CLI macOSCodex CLI WindowsCodex CLI Linux
MYAI168 API & MCPMYAI168 Chat API GuideMYAI168 MCP CLIMYAI168 MCP Web & App
User GuidesGT Agent GuideAI Services Guide
No matching questions on this page.Search the whole site
Endpoints and examples

OpenRouter API Relay

Base URL: https://www.myai168.com/en/api/openrouter/v1 (each endpoint URL = base URL + endpoint path; for the authentication, streaming, billing headers and error codes shared by all relays, see API Quick Start).

OpenRouter is an LLM gateway. One key gives access to hundreds of models (OpenAI / Anthropic / Google / Meta / Mistral, etc.) using vendor/model naming. Model ids differ from each vendor's own naming (Anthropic's claude-sonnet-5-5 is anthropic/claude-sonnet-5.5 on OpenRouter, for example), so use the id values returned by GET /models below. The key is your developer key from this site, not an OpenRouter key.

Endpoint overview

Endpoint (appended to the base URL)Purpose
POST /chat/completionsText conversation (Chat Completions format) with the chat models available on OpenRouter.
POST /chat/responsesSame as above (requests and responses are also in Chat Completions format — not the OpenAI Responses API).
POST /audio/speechText-to-speech (including ElevenLabs voices).
POST /audio/transcriptionsSpeech-to-text (including ElevenLabs Scribe).
POST /videos, GET /videos/{id}, GET /videos/{id}/contentVideo generation (asynchronous): submit a job, check its status, download the result.
GET /models, GET /videos/modelsModel lists (free).

POST https://www.myai168.com/en/api/openrouter/v1/chat/completions

Chat Completions (OpenAI format compatible). model and messages are required; the reply text is in choices[0].message.content.

curl https://www.myai168.com/en/api/openrouter/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"anthropic/claude-sonnet-5.5","messages":[{"role":"user","content":"Hello"}]}'
import requests

r = requests.post(
    "https://www.myai168.com/en/api/openrouter/v1/chat/completions",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"model": "anthropic/claude-sonnet-5.5", "messages": [{"role": "user", "content": "Hello"}]},
    timeout=600,
)
r.raise_for_status()
print(r.json()["choices"][0]["message"]["content"])
print("cost:", r.headers.get("X-Cost-Points"), "remaining:", r.headers.get("X-Credits-Remaining"))

POST https://www.myai168.com/en/api/openrouter/v1/chat/responses

Note: this endpoint is NOT the OpenAI Responses API — the request and response are both in Chat Completions format (same fields as completions above). It behaves the same as completions: both endpoints pre-check your credit balance and return 402 without forwarding when credits run out. For the OpenAI Responses API schema use https://www.myai168.com/en/api/openai/v1/responses instead.

curl https://www.myai168.com/en/api/openrouter/v1/chat/responses \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"openai/gpt-6.1-sol","messages":[{"role":"user","content":"Hello"}]}'
import requests

r = requests.post(
    "https://www.myai168.com/en/api/openrouter/v1/chat/responses",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"model": "openai/gpt-6.1-sol", "messages": [{"role": "user", "content": "Hello"}]},
)
print(r.json())

POST https://www.myai168.com/en/api/openrouter/v1/audio/speech

Text-to-speech (forwarded by OpenRouter to the speech provider); returns binary audio. This relay accepts the OpenRouter speech models of its model list that are billed per input character (Fish Audio: per UTF-8 byte), for example the whole ElevenLabs family (see below), hexgrad/kokoro-82m, mistralai/voxtral-mini-tts-2603, x-ai/grok-voice-tts-1.0 and fish-audio/s2.1-pro; models billed by audio length (such as Gemini TTS and Seed Audio) are not accepted (use this site's Google relay for Gemini TTS). voice depends on the model (e.g. af_bella for kokoro) — see the model page on OpenRouter; response_format is mp3 or pcm (default pcm). GET /models lists the speech models too.

ElevenLabs speech models: every ElevenLabs text-to-speech model on OpenRouter is billed per input character and is accepted by this relay — elevenlabs/eleven-v4 (most expressive, 90+ languages, up to 10,000 characters per request), elevenlabs/eleven-v4-turbo (low-latency v4, 90+ languages), elevenlabs/eleven-v3 (emotionally rich, 70+ languages, up to 5,000 characters), elevenlabs/eleven-v3-conversational (v3 tuned for dialogue, 70+ languages, up to 5,000 characters), elevenlabs/eleven-multilingual-v2 (long-form narration such as voice-overs and audiobooks, 29 languages, up to 10,000 characters), elevenlabs/eleven-flash-v2.5 and elevenlabs/eleven-turbo-v2.5 (low latency, 32 languages, up to 40,000 characters), elevenlabs/eleven-flash-v2 and elevenlabs/eleven-turbo-v2 (English only, low latency, up to 30,000 characters). voice is an ElevenLabs voice name (shared by all of these models, 21 in total): george, sarah, adam, alice, bella, bill, brian, callum, charlie, chris, daniel, eric, harry, jessica, laura, liam, lily, matilda, river, roger, will. The v3 / v4 models accept inline audio tags in square brackets (for example [excited], [whispers], [laughs]) to control emotion and delivery; keep the input within each model's per-request character limit (longer requests are rejected upstream and not charged). See the ElevenLabs page on OpenRouter for model details.

curl https://www.myai168.com/en/api/openrouter/v1/audio/speech \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"hexgrad/kokoro-82m","input":"Hello","voice":"af_bella","response_format":"mp3"}' \
  --output speech.mp3
import requests

r = requests.post(
    "https://www.myai168.com/en/api/openrouter/v1/audio/speech",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"model": "hexgrad/kokoro-82m", "input": "Hello", "voice": "af_bella", "response_format": "mp3"},
)
with open("speech.mp3", "wb") as f:
    f.write(r.content)

ElevenLabs example (model elevenlabs/eleven-v3, voices george / sarah):

curl https://www.myai168.com/en/api/openrouter/v1/audio/speech \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"elevenlabs/eleven-v3","input":"[excited] Hello! Welcome to our store.","voice":"george","response_format":"mp3"}' \
  --output speech_elevenlabs.mp3
import requests

r = requests.post(
    "https://www.myai168.com/en/api/openrouter/v1/audio/speech",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"model": "elevenlabs/eleven-v3", "input": "Hello! Welcome to our store.", "voice": "sarah", "response_format": "mp3"},
)
r.raise_for_status()
with open("speech_elevenlabs.mp3", "wb") as f:
    f.write(r.content)
print("cost:", r.headers.get("X-Cost-Points"), "remaining:", r.headers.get("X-Credits-Remaining"))

POST https://www.myai168.com/en/api/openrouter/v1/audio/transcriptions

Speech-to-text (multipart upload; the upstream limit for file is 25 MB). This relay accepts every speech-to-text model of its model list (GET /models), for example openai/whisper-1, openai/gpt-4o-transcribe, x-ai/grok-stt-2.0 and ElevenLabs Scribe: elevenlabs/scribe-v2 (90+ languages, with word-level timestamps, speaker diarization and audio-event tags) and elevenlabs/scribe-v2-medical (tuned for clinical and medical terminology). response_format is json (default) or verbose_json (adds language, duration and segments; add timestamp_granularities[]=word for word timestamps and diarize=true for speaker diarization — both require verbose_json); language takes an ISO-639-1 code (auto-detected when omitted). Points are charged by the actual usage of the audio; the X-Cost-Points response header shows the charge for the call.

curl https://www.myai168.com/en/api/openrouter/v1/audio/transcriptions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F file=@audio.mp3 \
  -F model=openai/whisper-1
import requests

with open("audio.mp3", "rb") as f:
    r = requests.post(
        "https://www.myai168.com/en/api/openrouter/v1/audio/transcriptions",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        files={"file": f},
        data={"model": "openai/whisper-1"},
    )
print(r.json())

ElevenLabs Scribe example (verbose_json with word timestamps and speaker diarization):

curl https://www.myai168.com/en/api/openrouter/v1/audio/transcriptions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F file=@meeting.mp3 \
  -F model=elevenlabs/scribe-v2 \
  -F response_format=verbose_json \
  -F "timestamp_granularities[]=word" \
  -F diarize=true
import requests

with open("meeting.mp3", "rb") as f:
    r = requests.post(
        "https://www.myai168.com/en/api/openrouter/v1/audio/transcriptions",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        files={"file": f},
        data={"model": "elevenlabs/scribe-v2", "language": "en"},
    )
r.raise_for_status()
print(r.json()["text"])
print("cost:", r.headers.get("X-Cost-Points"), "remaining:", r.headers.get("X-Credits-Remaining"))

POST https://www.myai168.com/en/api/openrouter/v1/videos

Video generation (an asynchronous job, matching the OpenRouter video API; the old path https://www.myai168.com/en/api/openrouter/v1/video/generations still works and behaves the same). The request returns 202 with the job right away; generation usually takes from tens of seconds to several minutes, so poll the polling_url until status is completed, then download the result. For the available models and each model's supported durations, resolutions and aspect ratios, call GET https://www.myai168.com/en/api/openrouter/v1/videos/models.

curl https://www.myai168.com/en/api/openrouter/v1/videos \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"google/veo-3.1","prompt":"A cat dancing","duration":8,"resolution":"720p","aspect_ratio":"16:9"}'
{"id": "gen-vid-1790000000-AbCdEf.123456", "polling_url": "https://www.myai168.com/en/api/openrouter/v1/videos/gen-vid-1790000000-AbCdEf.123456", "status": "pending"}

GET https://www.myai168.com/en/api/openrouter/v1/videos/{id}

Check the job status (pending / in_progress / completed / failed / cancelled / expired). Use the id returned when you submitted (this site's job id, which differs from OpenRouter's own id); only the submitter's API keys can see the job. When completed, the response includes unsigned_urls (download URLs for the results).

GET https://www.myai168.com/en/api/openrouter/v1/videos/{id}/content?index=0

Download a result (the API key is required here too); index selects which result (default 0).

import time
import requests

base = "https://www.myai168.com/en/api/openrouter/v1"
headers = {"Authorization": "Bearer YOUR_API_KEY"}

job = requests.post(f"{base}/videos", headers=headers, json={
    "model": "google/veo-3.1",
    "prompt": "A cat dancing",
    "duration": 8,
}).json()

while True:
    time.sleep(30)
    status = requests.get(job["polling_url"], headers=headers).json()
    if status["status"] == "completed":
        video = requests.get(status["unsigned_urls"][0], headers=headers)
        with open("video.mp4", "wb") as f:
            f.write(video.content)
        break
    if status["status"] in ("failed", "cancelled", "expired"):
        print(status.get("error"))
        break

Charges: credits are deducted by actual usage when the video completes (failed, cancelled or expired jobs are not charged); after completion, the poll response header X-Cost-Points shows the points charged for the job and X-Credits-Remaining your current balance. You need enough credits to submit, otherwise you get 402. callback_url (webhooks) is not supported — poll for the result; for previous_job_id (extending or editing an earlier video) pass the job id this site returned. Checking job status and downloading results are free.

GET https://www.myai168.com/en/api/openrouter/v1/models

List the OpenRouter models this relay accepts — text, speech, speech-to-text and video models (from the official OpenRouter list, cached 10 minutes; query endpoint, free). A model that is not in this list is refused with 400 "No pricing info! Please use other models!". Each id is what to put in the model field; entries also include context_length and supported_parameters (the parameters that model supports). Video models are listed by GET /videos/models.

curl "https://www.myai168.com/en/api/openrouter/v1/models" \
  -H "Authorization: Bearer YOUR_API_KEY"
curl "https://www.myai168.com/en/api/openrouter/v1/videos/models" \
  -H "Authorization: Bearer YOUR_API_KEY"
Common feature examples (multi-turn, image input, reasoning, fallback models, streaming)

Common feature examples

The request format is the same as OpenAI Chat Completions, plus OpenRouter's own extension fields. Feature availability depends on the selected model (see supported_parameters from GET /models).

1. System prompt and multi-turn conversations

The system prompt is the first system message; for multi-turn conversations put the earlier turns in messages in order. The API keeps no conversation state, so send the full history every time.

curl https://www.myai168.com/en/api/openrouter/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5.5",
    "messages": [
      {"role": "system", "content": "You are a concise assistant. Always answer in Traditional Chinese."},
      {"role": "user", "content": "Recommend three books on time management."},
      {"role": "assistant", "content": "1. Getting Things Done 2. Deep Work 3. Atomic Habits"},
      {"role": "user", "content": "Which one is best for beginners?"}
    ]
  }'

2. Image input

For models that accept images, make content an array and pass images as image_url (a public URL, or base64 in the form data:image/jpeg;base64,...).

curl https://www.myai168.com/en/api/openrouter/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5.5",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "What is in this image?"},
        {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
      ]
    }]
  }'

3. Reasoning effort

OpenRouter uses a unified reasoning field for every vendor's reasoning models: {"effort": "low" | "medium" | "high"}, or {"max_tokens": 4000} to cap thinking tokens; add "exclude": true to leave the reasoning out of the response. Returned reasoning text is in choices[0].message.reasoning.

curl https://www.myai168.com/en/api/openrouter/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-6.1-sol",
    "reasoning": {"effort": "high"},
    "messages": [{"role": "user", "content": "Prove that the square root of 2 is irrational."}]
  }'

4. Fallback models and provider routing

The models array lists fallback models: when the first cannot serve the request, the next one is used automatically (the model actually used is in the response model field). provider sets provider preferences, such as {"sort": "throughput"} (prefer faster output), {"sort": "latency"}, or {"order": ["anthropic"], "allow_fallbacks": false} to pin a provider.

curl https://www.myai168.com/en/api/openrouter/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "models": ["anthropic/claude-sonnet-5.5", "openai/gpt-6.1-sol"],
    "provider": {"sort": "throughput"},
    "messages": [{"role": "user", "content": "Hello"}]
  }'

5. Function calling and JSON output

tools / tool_choice (function calling) and response_format ({"type": "json_schema", ...} structured output) are written exactly as in OpenAI Chat Completions — see the Chat Completions forms in "Common feature examples" on the OpenAI ChatGPT API page; support depends on the model.

6. Streaming

Add "stream": true to receive the reply as SSE; use -N with curl. Text increments are in choices[0].delta.content, the last chunk carries usage, the stream ends with data: [DONE], and SSE comment lines then report the points charged and the remaining balance. While waiting for the model, OpenRouter sends keep-alive comment lines starting with : (such as : OPENROUTER PROCESSING); skip them when parsing.

curl -N https://www.myai168.com/en/api/openrouter/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"anthropic/claude-sonnet-5.5","stream":true,"messages":[{"role":"user","content":"Hello"}]}'
data: {"id":"gen-...","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hi"},"index":0}]}

data: {"id":"gen-...","object":"chat.completion.chunk","choices":[{"delta":{},"finish_reason":"stop","index":0}]}

data: {"id":"gen-...","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":8,"completion_tokens":12,"total_tokens":20}}

data: [DONE]

: cost=12
: credits-remaining=34567
Request parameters, response format and error codes

Request parameters (chat/completions and chat/responses)

Both endpoints take a Chat Completions format JSON body (chat/responses is not the OpenAI Responses API — it behaves the same as completions). Authenticate with an Authorization: Bearer YOUR_API_KEY header (never place keys in URL query strings).

ParameterTypeRequiredDescription
modelstringrequiredOpenRouter model id in vendor/model form (e.g. anthropic/claude-sonnet-5.5).
messagesarrayrequiredConversation messages (OpenAI Chat Completions format). role / content are forwarded as-is per the official format (including tool and other roles, and content-part arrays); support depends on the selected model.
streambooleanoptionaltrue streams the response as SSE.
max_tokensintegeroptionalUpper limit on reply tokens.
reasoningobjectoptionalReasoning settings: effort, max_tokens, exclude.
models / providerarray / objectoptionalFallback models and provider routing (OpenRouter extension fields).
tools / tool_choice / response_format—optionalFunction calling and JSON output (OpenAI format).
Other official parameters—optionaltemperature, top_p, stop, seed and so on are forwarded to OpenRouter as-is.

Response format

OpenAI Chat Completions compatible: text in choices[0].message.content (streaming deltas in choices[0].delta.content). Each successful call is charged by usage; non-streaming responses carry X-Cost-Points (points charged) and X-Credits-Remaining (balance after the call) headers, and streaming responses append the same information after the stream ends as SSE comment lines : cost=N / : credits-remaining=M. You can also query your balance any time with GET https://www.myai168.com/en/api/user/get_credits.

The response usage carries token counts (prompt_tokens / completion_tokens / total_tokens); for the points charged, read the headers or comment lines above. choices[0].finish_reason is stop (normal end), length (token limit reached), tool_calls (a function call is requested) or content_filter.

Error codes

HTTP statusMeaning
400Invalid request body (for example a missing model), or a model that is not in the relay's model list GET /models — including any entry of a models fallback list ("No pricing info! Please use other models!") / a speech model billed by audio length. A 400 returned by OpenRouter (such as an unknown model id) is also passed through unchanged.
401Missing or invalid API key (repeated failures from the same IP are temporarily blocked), or this API key has reached its credit limit (API key credit limit reached!).
402Insufficient credits (chat/responses / audio / video endpoints block before forwarding).
404The video job id does not exist or was not submitted by this account.
429 / 5xxRate limiting or overload reported by OpenRouter or its providers — the status code and error body are passed through unchanged; retry later or switch to another model.
502Upstream vendor error — never charged.

Error responses are JSON with the message in error.message, for example:

{"error": {"type": "invalid_request", "message": "Missing \"model\" field in request body."}}

No points are ever charged on errors, including a stream cut off midway. The relay waits up to about 10 minutes for the model; prefer streaming for long outputs.

Using the official OpenAI SDK (Python / Node.js)

Calling the OpenRouter relay with the official OpenAI SDK

The chat endpoints are OpenAI Chat Completions compatible, so the official OpenAI SDK works directly: set base_url (baseURL in Node.js) to https://www.myai168.com/en/api/openrouter/v1 and api_key to your developer key from this site, and call client.chat.completions (not client.responses).

Python

from openai import OpenAI

client = OpenAI(
    base_url="https://www.myai168.com/en/api/openrouter/v1",
    api_key="YOUR_API_KEY",
)

chat = client.chat.completions.create(
    model="anthropic/claude-sonnet-5.5",
    messages=[{"role": "user", "content": "Hello"}],
)
print(chat.choices[0].message.content)

# Streaming
stream = client.chat.completions.create(
    model="anthropic/claude-sonnet-5.5",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

# OpenRouter-specific fields go through extra_body
chat = client.chat.completions.create(
    model="openai/gpt-6.1-sol",
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={"reasoning": {"effort": "high"}, "provider": {"sort": "throughput"}},
)

Node.js

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://www.myai168.com/en/api/openrouter/v1",
  apiKey: "YOUR_API_KEY",
});

const chat = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-5.5",
  messages: [{ role: "user", content: "Hello" }],
});
console.log(chat.choices[0].message.content);

OpenRouter's own extension fields (reasoning, provider, models) are not SDK parameters: in Python put them in extra_body; in Node.js add them to the same object. The SDK skips comment lines in the stream automatically.

‹ Previous page: Google News APINext page: API Pricing ›
↑
Question link copied.

Other FAQ pages

API Documentation

  • API Quick Start
  • OpenAI ChatGPT API
  • Anthropic (Claude) API
  • Google Gemini API
  • Google Search API
  • Google News API
  • API Pricing

CLI & Agent Guides

  • cc-switch macOS
  • cc-switch Windows
  • cc-switch Linux
  • OpenCode macOS
  • OpenCode Windows
  • OpenCode Linux
  • OpenClaw macOS
  • OpenClaw Windows
  • OpenClaw Linux
  • Hermes Agent macOS
  • Hermes Agent Windows
  • Hermes Agent Linux
  • Claude Code CLI macOS
  • Claude Code CLI Windows
  • Claude Code CLI Linux
  • Codex CLI macOS
  • Codex CLI Windows
  • Codex CLI Linux

MYAI168 API & MCP

  • MYAI168 Chat API Guide
  • MYAI168 MCP CLI
  • MYAI168 MCP Web & App

User Guides

  • GT Agent Guide
  • AI Services Guide