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 } 要求返回;此时 usage 会在最后一个数据块里以空的 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 不会添加自己的系统提示词。每个模型自己的使用政策同样适用。扣费结算后,消息内容不会被保留。

本页内容