PopNowAPI 文件
對話與相容介面
主要內容

聊天模型

用你已經在用的 OpenAI、Anthropic 或 Gemini SDK,透過 PopNow API 呼叫 Claude、Gemini、DeepSeek、GLM、Grok 和 Kimi。一個 API 金鑰,按 token 以美元計價。

PopNow API 也提供聊天模型:Claude、Gemini、DeepSeek、GLM、Grok 和 Kimi。透過你已經在用的協定呼叫——OpenAI Chat Completions 與 Responses、Anthropic Messages、Gemini generateContent——修改基底網址後即可繼續使用官方 SDK。它們與 API 圖片、影片和音訊共用 sk-popnow- 金鑰,以及獨立的 API 美元餘額。餘額初始為 $0,請在 API 帳單儲值;網站點數不能支付這些呼叫。

聊天呼叫是同步的:回覆(或串流)在同一個回應中回傳,沒有需要輪詢的任務。

概覽

OpenAI base URLhttps://api.popnow.ai/v1(Chat Completions、Responses、模型清單)
Anthropic base URLhttps://api.popnow.ai(SDK 會自動加上 /v1/messages)
GeminiPOST https://api.popnow.ai/v1beta/models/{model}:generateContent
金鑰Authorization: Bearer sk-popnow-…;Anthropic SDK 的 x-api-key 和 Google 的 x-goog-api-key 請求標頭同樣有效
模型 IDpublisher/model/chat,例如 anthropic/claude-haiku-5.5/chat。完整清單見下方
價格按 token 以美元計費,沒有單次請求最低消費。失敗和被拒絕的請求會全額退還
串流輸出所有協定都支援 stream: true(Gemini 使用 :streamGenerateContent?alt=sse)

第一個聊天請求

curl https://api.popnow.ai/v1/chat/completions \
  -H "Authorization: Bearer $POPNOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-haiku-5.5/chat",
    "messages": [
      { "role": "system", "content": "You are a concise, friendly assistant." },
      { "role": "user", "content": "Suggest three names for a kite shop by the sea." }
    ],
    "max_tokens": 512
  }'

回覆是標準的 chat.completion 物件,包含 choices[0].message.content 和 usage。回應標頭 X-PopNow-Task-Id 提供紀錄這筆收費的任務。

OpenAI SDK

把用戶端指向 https://api.popnow.ai/v1,並傳入你的 PopNow 金鑰即可,其他都不用改。

Python
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.popnow.ai/v1", api_key=os.environ["POPNOW_API_KEY"])

reply = client.chat.completions.create(
    model="anthropic/claude-haiku-5.5/chat",
    messages=[{"role": "user", "content": "Write a haiku about kites."}],
    max_tokens=200,
)
print(reply.choices[0].message.content)
JavaScript (Node.js 18+)
import OpenAI from 'openai';

const client = new OpenAI({ baseURL: 'https://api.popnow.ai/v1', apiKey: process.env.POPNOW_API_KEY });

const reply = await client.chat.completions.create({
  model: 'google/gemini-3.7-flash/chat',
  messages: [{ role: 'user', content: 'Write a haiku about kites.' }],
  max_tokens: 200,
});
console.log(reply.choices[0].message.content);

Responses API(client.responses.create)也可以用,但只能是無狀態形式:每次都要在 input 裡傳送完整的對話。傳入 previous_response_id 會回傳 400。

Anthropic SDK

Anthropic SDK 會自己加上 /v1/messages,所以 base URL 不帶 /v1。

Python
import os
import anthropic

client = anthropic.Anthropic(base_url="https://api.popnow.ai", api_key=os.environ["POPNOW_API_KEY"])

message = client.messages.create(
    model="anthropic/claude-sonnet-5.5/chat",
    max_tokens=512,
    messages=[{"role": "user", "content": "Explain idempotency keys in two sentences."}],
)
print(message.content[0].text)

這個端點上的任何聊天模型都能用,不只是 Claude。錯誤以 Anthropic 的 {"type": "error", "error": {...}} 格式回傳。

Gemini generateContent

把完整的模型 ID 放在路徑裡;它可以包含斜線。

curl "https://api.popnow.ai/v1beta/models/google/gemini-3.7-flash/chat:generateContent" \
  -H "Authorization: Bearer $POPNOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{ "role": "user", "parts": [{ "text": "Name three colours of a sunset." }] }],
    "generationConfig": { "maxOutputTokens": 256 }
  }'

需要串流輸出時,使用 :streamGenerateContent?alt=sse。錯誤使用 Google 的 {"error": {"code", "message", "status"}} 格式。

串流輸出

設定 stream: true,然後讀取 Server-Sent Events。在 Chat Completions 上,每個資料區塊都是 chat.completion.chunk,串流以 data: [DONE] 結束。和 OpenAI 一樣,串流中預設不包含 usage,除非你用 stream_options: { "include_usage": true } 要求回傳;此時用量會在最後一個資料區塊中回傳,並附上空的 choices 陣列。

Python
stream = client.chat.completions.create(
    model="anthropic/claude-haiku-5.5/chat",
    messages=[{"role": "user", "content": "Count from one to five."}],
    max_tokens=100,
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

工具、JSON 輸出與參數

每個模型都宣告了它接受的請求欄位,例如 tools、tool_choice、response_format、temperature、reasoning_effort 等。模型表中的參數欄列出了這些欄位,GET /v1/models 則會在 supported_parameters 中回傳它們。

  • 模型不支援的取樣參數(temperature、top_p、frequency_penalty 等)會被丟棄,而不是直接報錯,並在 X-PopNow-Ignored-Params 回應標頭中列出。
  • 超出模型取值範圍的值會被調整為最接近的可接受值,並以 name=value 的形式出現在 X-PopNow-Adjusted-Params 中。
  • 模型未宣告的其他欄位會回傳 400,附帶 code: unsupported_parameter,param 指明是哪個欄位;例如把圖片內容塊發給純文字模型。

模型與價格

按每 100 萬 token的美元價格計,輸入和輸出分別定價;支援快取的模型,快取輸入更便宜。有些模型在請求超過長上下文門檻後會使用較高價格,門檻標在模型名稱下方。

模型模型 ID上下文輸入(每百萬 token) (USD)輸出(每百萬 token) (USD)參數
Claude Fable 5Anthropicanthropic/claude-fable-5/chat1M最大輸出 128K$9快取 $0.9快取寫入 $11$45max_tokensparallel_tool_callsreasoning_effortstoptool_choicetools
Claude Haiku 5.5Anthropic單次輸入 > 100K token 時: $0.5 / $2.5 · 快取 $0.1anthropic/claude-haiku-5.5/chat1M最大輸出 128K$0.1快取寫入 $0.1$0.5max_tokensparallel_tool_callstool_choicetools
Claude Opus 4.5Anthropicanthropic/claude-opus-4.5/chat198K最大輸出 33K$4.5快取 $0.45快取寫入 $5.5$22.5max_tokensparallel_tool_callsreasoning_effortstoptemperaturetool_choicetoolstop_p
Claude Opus 4.6Anthropicanthropic/claude-opus-4.6/chat1M最大輸出 128K$5快取 $0.5快取寫入 $6.25$25max_tokensparallel_tool_callsreasoning_effortstoptemperaturetool_choicetoolstop_p
Claude Opus 5Anthropicanthropic/claude-opus-5/chat1M最大輸出 128K$4.5快取 $0.45快取寫入 $5.5$22.5max_tokensparallel_tool_callsreasoning_effortstoptool_choicetools
Claude Opus 5.5Anthropicanthropic/claude-opus-5.5/chat1M最大輸出 128K$3.6快取 $0.18快取寫入 $4.5$18max_tokensparallel_tool_callsreasoning_effortstoptool_choicetools
Claude Sonnet 4.5Anthropicanthropic/claude-sonnet-4.5/chat198K最大輸出 64K$2.7快取 $0.27快取寫入 $3.3$13.5max_tokensparallel_tool_callsstoptemperaturetool_choicetoolstop_ktop_p
Claude Sonnet 4.6Anthropicanthropic/claude-sonnet-4.6/chat1M最大輸出 64K$3快取 $0.3快取寫入 $3.75$15max_tokensparallel_tool_callsreasoning_effortstoptemperaturetool_choicetoolstop_ktop_p
Claude Sonnet 5Anthropicanthropic/claude-sonnet-5/chat1M最大輸出 64K$1.9快取 $0.19快取寫入 $2.375$9.5max_tokensparallel_tool_callsreasoning_effortstoptool_choicetools
Claude Sonnet 5.5Anthropicanthropic/claude-sonnet-5.5/chat1M最大輸出 128K$2快取 $0.2快取寫入 $2.5$10max_tokensparallel_tool_callsreasoning_effortstoptool_choicetools
DeepSeek V4.1 FlashDeepSeekdeepseek/v4.1-flash/chat1M最大輸出 384K$0.3快取 $0.006$1.2max_tokensreasoning_effortresponse_formatstoptool_choicetools
DeepSeek V4 FlashDeepSeekdeepseek/v4-flash/chat1M最大輸出 66K$0.44快取 $0.014$1.32max_tokensreasoning_effortresponse_formatstoptool_choicetools
DeepSeek V4 ProDeepSeekdeepseek/v4-pro/chat1M最大輸出 384K$1.32快取 $0.044$3.96max_tokensparallel_tool_callsreasoning_effortresponse_formatstoptool_choicetools
Gemini 2.5 FlashGooglegoogle/gemini-2.5-flash/chat1M最大輸出 66K$0.285快取 $0.0285$2.375max_tokensreasoning_effortresponse_formatseedstoptemperaturetool_choicetoolstop_p
Gemini 3.1 Pro PreviewGoogle單次輸入 > 200K token 時: $3.8 / $17.1 · 快取 $0.38google/gemini-3.1-pro-preview/chat1M最大輸出 33K$1.9快取 $0.19$11.4max_tokensreasoning_effortresponse_formatseedstoptemperaturetool_choicetoolstop_p
Gemini 3.5 Flash-LiteGooglegoogle/gemini-3.5-flash-lite/chat1M最大輸出 66K$0.3快取 $0.03$2.5max_tokensreasoning_effortresponse_formatseedstoptemperaturetool_choicetoolstop_p
Gemini 3.7 FlashGooglegoogle/gemini-3.7-flash/chat1M最大輸出 66K$0.675快取 $0.0675$3.375max_tokensreasoning_effortresponse_formatseedstoptemperaturetool_choicetoolstop_p
Gemini 3 Flash PreviewGooglegoogle/gemini-3-flash-preview/chat256K最大輸出 66K$0.45快取 $0.045$2.7max_tokensreasoning_effortresponse_formatseedstoptemperaturetool_choicetoolstop_p
GLM 5.2Z.aizai/glm-5.2/chat1M最大輸出 131K$0.98快取 $0.182$3.08max_tokensreasoning_effortresponse_formatstoptemperaturetool_choicetoolstop_p
GLM 5.3Z.aizai/glm-5.3/chat1M最大輸出 131K$1.05快取 $0.195$3.3max_tokensparallel_tool_callsreasoning_effortresponse_formatseedstoptemperaturetool_choicetoolstop_p
GLM 5.3 FlashZ.aizai/glm-5.3-flash/chat1M最大輸出 131K$0.1275快取 $0.0255$0.425max_tokensreasoning_effortresponse_formatstoptemperaturetool_choicetoolstop_p
Grok 4.3xAI單次輸入 ≥ 200K token 時: $2.5 / $5 · 快取 $0.4xai/grok-4.3/chat1M最大輸出 900K$1.25快取 $0.2$2.5max_tokensparallel_tool_callsreasoning_effortresponse_formattemperaturetool_choicetoolstop_p
Grok 4.5xAI單次輸入 ≥ 200K token 時: $4 / $12 · 快取 $0.6xai/grok-4.5/chat500K最大輸出 450K$2快取 $0.3$6max_tokensparallel_tool_callsreasoning_effortresponse_formattemperaturetool_choicetoolstop_p
Grok 4.6xAI單次輸入 ≥ 200K token 時: $4 / $12 · 快取 $1xai/grok-4.6/chat500K最大輸出 450K$2快取 $0.5$6max_tokensparallel_tool_callsreasoning_effortresponse_formattemperaturetool_choicetoolstop_p
Grok 4.7xAI單次輸入 ≥ 200K token 時: $4 / $12 · 快取 $1xai/grok-4.7/chat500K最大輸出 450K$2快取 $0.5$6max_tokensparallel_tool_callsreasoning_effortresponse_formattemperaturetool_choicetoolstop_p
Kimi K3Moonshot AImoonshot/kimi-k3/chat1M最大輸出 1M$2.7快取 $0.3$13.5max_tokensreasoning_effortresponse_formatstoptool_choicetools

同樣的清單也可以透過 API 取得,包含價格、上下文長度和支援的參數:

curl "https://api.popnow.ai/v1/models?modality=text" \
  -H "Authorization: Bearer $POPNOW_API_KEY"

聊天請求如何計費

  1. 保留。 請求被受理時,系統會根據輸入和 max_tokens 估算最高費用,並從餘額中保留這筆金額。如果你不設定 max_tokens,會按模型的最大輸出計算,所以請設定它,以減小保留額。
  2. 收費。 回覆結束後,按實際使用的 token 以美元結算,沒有單次請求最低消費。其餘保留金額釋放。
  3. 退款。 失敗的請求,或被模型拒絕的請求,會全額退款。

餘額不足以支付保留金額,或會超過金鑰的消費上限時,請求在送到模型前就回傳 402。要查看確切費用,以回應標頭 X-PopNow-Task-Id 中的任務 ID 查詢 GET /api/v1/jobs/recordInfo:costUsd 是用於顯示與對帳的美元十進位字串。回應裡可能仍有舊點數欄位;不要把美元費用以整數點數進位。

長回覆與錯誤

  • 長時間的非串流呼叫。 如果回覆超過約 30 秒,會先傳送 200 狀態和 X-PopNow-Keepalive: 1 回應標頭,之後每 15 秒傳送一個換行,最後才是 JSON 內容。在那之後發生的失敗,會以協定常規的錯誤物件出現在 200 內容中,所以當該回應標頭存在時,請檢查是否有 error 鍵。串流呼叫可以避免這個問題。
  • 404 model_not_found。 模型 ID 不存在。錯誤訊息會提供你可以呼叫的最接近的聊天模型。
  • 400 且 param: model。 這個 ID 屬於圖片、影片或音訊模型;這些模型以任務的形式執行。
  • 400 content_rejected。 模型自身的內容政策拒絕了這個請求。不收費。
  • 402。 API 美元餘額不足以保留所需金額,或達到金鑰消費上限。請見 API 計費。

隱私

請求會按你編寫的原樣傳送給模型;PopNow 不會新增自己的系統提示詞。每個模型自己的使用政策同樣適用。費用結算後,訊息內容不會被保留。

本頁內容