首頁›開發者中心›OpenAI ChatGPT API

OpenAI ChatGPT 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 網頁及應用程式
本頁沒有符合的問題。改用全站搜尋
OpenAI

OpenAI API 中繼

POST https://www.myai168.com/nccu/api/openai/v1/responses

Responses API (新版對話介面,支援 streaming)。

curl https://www.myai168.com/nccu/api/openai/v1/responses \
  -H "Authorization: Bearer YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-5.6-sol","input":"Hello"}'
import requests

r = requests.post(
    "https://www.myai168.com/nccu/api/openai/v1/responses",
    headers={"Authorization": "Bearer YOUR_DEV_KEY"},
    json={"model": "gpt-5.6-sol", "input": "Hello"},
)
print(r.json())

POST https://www.myai168.com/nccu/api/openai/v1/chat/completions

Chat Completions API (舊版對話介面,相容 OpenAI SDK)。

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

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

POST https://www.myai168.com/nccu/api/openai/v1/audio/speech

文字轉語音 (TTS),回 audio binary。

curl https://www.myai168.com/nccu/api/openai/v1/audio/speech \
  -H "Authorization: Bearer YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"tts-1","input":"Hello","voice":"nova"}' \
  --output speech.mp3
import requests

r = requests.post(
    "https://www.myai168.com/nccu/api/openai/v1/audio/speech",
    headers={"Authorization": "Bearer YOUR_DEV_KEY"},
    json={"model": "tts-1", "input": "Hello", "voice": "nova"},
)
with open("speech.mp3", "wb") as f:
    f.write(r.content)

POST https://www.myai168.com/nccu/api/openai/v1/audio/transcriptions

語音轉文字 (STT, multipart upload)。

curl https://www.myai168.com/nccu/api/openai/v1/audio/transcriptions \
  -H "Authorization: Bearer YOUR_DEV_KEY" \
  -F file=@audio.mp3 \
  -F model=gpt-4o-transcribe
import requests

with open("audio.mp3", "rb") as f:
    r = requests.post(
        "https://www.myai168.com/nccu/api/openai/v1/audio/transcriptions",
        headers={"Authorization": "Bearer YOUR_DEV_KEY"},
        files={"file": f},
        data={"model": "gpt-4o-transcribe"},
    )
print(r.json())

POST https://www.myai168.com/nccu/api/openai/v1/audio/translations

語音翻譯成英文 (STT + translate)。OpenAI 官方 translations 端點僅支援 whisper-1(gpt-4o-transcribe 僅 transcriptions 可用);範例帶 response_format=verbose_json 取得含時長的完整 JSON。

curl https://www.myai168.com/nccu/api/openai/v1/audio/translations \
  -H "Authorization: Bearer YOUR_DEV_KEY" \
  -F file=@audio.mp3 \
  -F model=whisper-1 \
  -F response_format=verbose_json
import requests

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

POST https://www.myai168.com/nccu/api/openai/v1/images/generations

文字生圖 (gpt-image-2)。

curl https://www.myai168.com/nccu/api/openai/v1/images/generations \
  -H "Authorization: Bearer YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-image-2","prompt":"A cute cat","size":"1024x1024"}'
import requests

r = requests.post(
    "https://www.myai168.com/nccu/api/openai/v1/images/generations",
    headers={"Authorization": "Bearer YOUR_DEV_KEY"},
    json={"model": "gpt-image-2", "prompt": "A cute cat", "size": "1024x1024"},
)
print(r.json())

POST https://www.myai168.com/nccu/api/openai/v1/embeddings

文字向量 (embeddings,OpenAI 相容格式;受理模型 voyage-4/voyage-4-large,依 input token 計費)。

curl https://www.myai168.com/nccu/api/openai/v1/embeddings \
  -H "Authorization: Bearer YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"voyage-4-large","input":"Hello"}'
import requests

r = requests.post(
    "https://www.myai168.com/nccu/api/openai/v1/embeddings",
    headers={"Authorization": "Bearer YOUR_DEV_KEY"},
    json={"model": "voyage-4-large", "input": "Hello"},
)
print(r.json())

GET https://www.myai168.com/nccu/api/openai/v1/audio/voices

列出可用的 TTS 內建語音 (查詢類,免費)。註:GET 列表屬本站擴充查詢——OpenAI 官方 API 參考僅記載 POST 建立自訂語音,無 GET 列表端點,請勿以官方 SDK 介面對照。

curl https://www.myai168.com/nccu/api/openai/v1/audio/voices \
  -H "Authorization: Bearer YOUR_DEV_KEY"

POST https://www.myai168.com/nccu/api/openai/v1/audio/voices

自訂語音建立 (聲音複製,multipart upload;欄位:audio_sample 語音樣本檔必填、consent 同意錄音 ID 必填(例 cons_1234——依 OpenAI 官方規格須先完成「同意錄音」上傳取得,不是授權聲明文字)、name 語音名稱)。官方目前僅開放具資格帳號建立自訂語音。

curl https://www.myai168.com/nccu/api/openai/v1/audio/voices \
  -H "Authorization: Bearer YOUR_DEV_KEY" \
  -F audio_sample=@sample.mp3 \
  -F consent="cons_1234" \
  -F name="My Voice"

GET https://www.myai168.com/nccu/api/openai/v1/models/GET https://www.myai168.com/nccu/api/openai/v1/models/{model}

查詢支援的模型清單/單一模型 (相容 SDK models.list/models.retrieve,查詢類,免費)。

curl https://www.myai168.com/nccu/api/openai/v1/models \
  -H "Authorization: Bearer YOUR_DEV_KEY"

curl https://www.myai168.com/nccu/api/openai/v1/models/gpt-5.6-sol \
  -H "Authorization: Bearer YOUR_DEV_KEY"
支援的端點與功能(支援矩陣)

支援矩陣

部分 OpenAI SDK 功能經本站中繼時行為不同,接入前請先對照本表,避免踩坑。

  • GET /v1/models 與 GET /v1/models/{model} —— 支援(相容 SDK models.list/models.retrieve)。回傳的清單就是本中繼實際受理的模型;不在清單內的模型一律回 "No pricing info! Please use other models!"。
  • POST /v1/responses 與 POST /v1/chat/completions —— 支援,含串流。
  • 網頁搜尋 —— 支援並按次計費:Responses API 用 tools: [{"type": "web_search"}],Chat Completions 用 web_search_options。
  • 其他 hosted 工具(code_interpreter、file_search、image_generation、computer use、hosted MCP)—— 不支援,回 HTTP 400;請改用 client 端 function calling。
  • 音訊端點(speech/transcriptions/translations/voices——GET 列出內建語音免費、POST 建立自訂語音)、images/generations 與 embeddings(受理模型 voyage-4/voyage-4-large)—— 支援。
  • 非串流回應帶 X-Cost-Points(本次扣點)與 X-Credits-Remaining(扣後餘額)header;串流回應則在最後一個事件(data: [DONE])之後以 SSE 註解行 : cost=N/: credits-remaining=M 附上相同資訊;也可隨時以 GET https://www.myai168.com/nccu/api/user/get_credits 查詢餘額。
  • 呼叫失敗或供應商未回用量資訊時,一律不收費。
請求參數、回應格式與錯誤碼

請求參數(POST https://www.myai168.com/nccu/api/openai/v1/chat/completions)

請求本體為 JSON,與 OpenAI 官方規格相同。認證帶 Authorization: Bearer YOUR_API_KEY 標頭(金鑰不可放在網址查詢參數)。

參數型別必填說明
modelstring必填模型代號(例 gpt-5.6-sol)。必須在 GET /v1/models 回傳清單內,否則回 400 與 "No pricing info! Please use other models!"。
messagesarray必填對話訊息陣列。role 支援官方全部角色:developer/system/user/assistant/tool(舊制 function 已棄用但仍受理);content 可為字串,或由文字/圖片/音訊組成的多段內容陣列(官方 content parts 格式)。
streamboolean選填true 時以 SSE 串流回應(data: {JSON} 逐段,最後 data: [DONE])。
web_search_optionsobject選填啟用網頁搜尋(按次計費)。
max_tokens/temperature/top_p/tools(function calling)等—選填其餘官方參數原樣透傳;hosted 工具(code_interpreter 等)不支援、回 400。

Responses API(POST /v1/responses)改用 input(string 或 array,必填)與 model(必填),可帶 tools: [{"type": "web_search"}] 啟用搜尋;其餘官方參數原樣透傳。

回應格式

非串流:官方 JSON——Chat Completions 的文字在 choices[0].message.content、用量在 usage;Responses 的文字要從 output[] 陣列解析(type 為 message 的項目中,content[] 內 type 為 output_text 區塊的 text 欄位)——output_text 是官方 Python/JavaScript SDK 的便利屬性,原始 REST JSON 沒有這個欄位。回應標頭另帶 X-Cost-Points(本次扣點)與 X-Credits-Remaining(扣後餘額)。

串流:SSE 逐段送出,Chat Completions 增量在 choices[0].delta.content,結束為 data: [DONE];結束後以 SSE 註解行 : cost=N/: credits-remaining=M 附上本次扣點與餘額(規範相容的 SSE 解析器與官方 SDK 會自動忽略註解行),也可隨時查 GET https://www.myai168.com/nccu/api/user/get_credits。

串流範例

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

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

data: [DONE]

錯誤碼

HTTP 狀態意義
401金鑰缺漏或無效(同 IP 連續失敗會被暫時封鎖)。
402點數不足(請先儲值)。
400請求本體格式錯誤、模型不在支援清單("No pricing info! Please use other models!"),或帶了不支援的 hosted 工具。
502上游供應商錯誤——一律不扣點。

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

下一頁:Anthropic (Claude) API ›
↑
已複製此問題的連結

其他常見問題頁面

API 說明文件

  • Anthropic (Claude) API
  • Google Gemini API
  • Google Search API
  • Google News API
  • OpenRouter 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 網頁及應用程式