首頁›開發者中心›OpenRouter API

OpenRouter API

API 說明文件OpenAI ChatGPT APIAnthropic (Claude) APIGoogle Gemini APIGoogle Search APIGoogle News APIOpenRouter APIAPI 收費
CLI 與 Agent 教學cc-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 MCP CLIMYAI168 MCP 網頁及應用程式
本頁沒有符合的問題。改用全站搜尋
OpenRouter

OpenRouter API 中繼

OpenRouter 是 LLM gateway,一個金鑰可呼叫數百種 model (OpenAI / Anthropic / Google / Meta / Mistral 等),model 名格式為 vendor/model。

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

Chat Completions (相容 OpenAI 格式)。

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

r = requests.post(
    "https://www.myai168.com/stu/api/openrouter/v1/chat/completions",
    headers={"Authorization": "Bearer YOUR_DEV_KEY"},
    json={"model": "anthropic/claude-sonnet-5", "messages": [{"role": "user", "content": "Hello"}]},
)
print(r.json())

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

注意:此端點不是 OpenAI Responses API——請求與回應皆為 Chat Completions 格式(欄位同上方 completions),行為與 completions 相同:兩端點都會在送出前先檢查點數餘額,點數不足直接回 402、不轉發上游。要用 OpenAI Responses API 格式請改用 https://www.myai168.com/stu/api/openai/v1/responses。

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

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

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

文字轉語音 (透過 OpenRouter 路由到 TTS 供應商)。注意:OpenRouter 未提供 openai/tts-1——現行 TTS 模型為 openai/gpt-4o-mini-tts-2025-12-15、mistralai/voxtral-mini-tts-2603 等帶版本的代號,請以 OpenRouter 官方模型清單為準。

curl https://www.myai168.com/stu/api/openrouter/v1/audio/speech \
  -H "Authorization: Bearer YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"openai/gpt-4o-mini-tts-2025-12-15","input":"Hello","voice":"nova"}' \
  --output speech.mp3
import requests

r = requests.post(
    "https://www.myai168.com/stu/api/openrouter/v1/audio/speech",
    headers={"Authorization": "Bearer YOUR_DEV_KEY"},
    json={"model": "openai/gpt-4o-mini-tts-2025-12-15", "input": "Hello", "voice": "nova"},
)
with open("speech.mp3", "wb") as f:
    f.write(r.content)

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

語音轉文字 (multipart upload)。OpenRouter 官方 STT 模型為 openai/whisper-1/openai/whisper-large-v3 等(未列 openai/gpt-4o-transcribe),本中繼受理 openai/whisper-1。

curl https://www.myai168.com/stu/api/openrouter/v1/audio/transcriptions \
  -H "Authorization: Bearer YOUR_DEV_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/stu/api/openrouter/v1/audio/transcriptions",
        headers={"Authorization": "Bearer YOUR_DEV_KEY"},
        files={"file": f},
        data={"model": "openai/whisper-1"},
    )
print(r.json())

POST https://www.myai168.com/stu/api/openrouter/v1/video/generations

影片生成 (依 OpenRouter 支援的 video model)。注意:範例中的 vendor/some-video-model 是佔位字串、不是可直接執行的模型代號——OpenRouter 影片端點屬新功能,可用模型請以 OpenRouter 官方公告為準;指定不支援的模型會由上游回 4xx(不扣點)。

curl https://www.myai168.com/stu/api/openrouter/v1/video/generations \
  -H "Authorization: Bearer YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"vendor/some-video-model","prompt":"A cat dancing"}'
import requests

r = requests.post(
    "https://www.myai168.com/stu/api/openrouter/v1/video/generations",
    headers={"Authorization": "Bearer YOUR_DEV_KEY"},
    json={"model": "vendor/some-video-model", "prompt": "A cat dancing"},
)
print(r.json())
請求參數、回應格式與錯誤碼

請求參數(chat/completions 與 chat/responses)

兩端點的請求本體都是 Chat Completions 格式 JSON(chat/responses 不是 OpenAI Responses API,行為與 completions 相同)。認證帶 Authorization: Bearer YOUR_API_KEY 標頭(金鑰不可放在網址查詢參數)。

參數型別必填說明
modelstring必填OpenRouter 模型代號,格式 vendor/model(例 anthropic/claude-sonnet-5)。
messagesarray必填對話訊息陣列(OpenAI Chat Completions 格式)。role/content 依官方格式原樣透傳(含 tool 等其他角色與多段內容陣列),支援程度依所選模型而定。
streamboolean選填true 時以 SSE 串流回應。
其餘官方參數—選填原樣透傳 OpenRouter。

回應格式

與 OpenAI Chat Completions 相容:文字在 choices[0].message.content(串流增量在 choices[0].delta.content)。計費依 OpenRouter 回報的實際費用換算點數;非串流回應帶 X-Cost-Points(本次扣點)與 X-Credits-Remaining(扣後餘額)標頭,串流結束後以 SSE 註解行 : cost=N/: credits-remaining=M 附上相同資訊;餘額也可隨時以 GET https://www.myai168.com/stu/api/user/get_credits 查詢。

錯誤碼

HTTP 狀態意義
401金鑰缺漏或無效(同 IP 連續失敗會被暫時封鎖)。
402點數不足(chat/responses/音訊/影片端點會在送出前先擋下)。
400請求本體格式錯誤,或音訊端點指定了無計價資訊的模型("No pricing info! Please use other models!")。
502上游供應商錯誤——一律不扣點。

任何錯誤(含供應商未回用量/費用資訊)一律不扣點。

‹ 上一頁:Google News API下一頁:API 收費 ›
↑
已複製此問題的連結

其他常見問題頁面

API 說明文件

  • OpenAI ChatGPT API
  • Anthropic (Claude) API
  • Google Gemini API
  • Google Search API
  • Google News API
  • API 收費

CLI 與 Agent 教學

  • 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 MCP CLI
  • MYAI168 MCP 網頁及應用程式