开始前:地址与协议
本页介绍通过 DAYWORLD 调用 DeepSeek。示例默认使用京东云 Flash 模型 deepseek-flash。先取得本站 API Key,再从当前 Key 的模型目录确认可用模型与协议。
| 用途 | 地址 | 填写方式 |
|---|---|---|
| OpenAI SDK Base URL | https://api.example.com/v1 | 用于 Chat Completions 和 Responses;SDK 自动追加接口路径。 |
| Chat Completions | POST /v1/chat/completions | model + messages |
| Responses | POST /v1/responses | model + input |
| Anthropic SDK Base URL | https://api.example.com | SDK 自动追加 /v1/messages;本站不需要添加 /anthropic。 |
| 可用模型 | GET /v1/models | 携带要使用的 API Key,读取 data[].id。 |
API 接入地址、接入线路及可记录字段,在服务开通时确认;接入线路不代表模型推理与全部数据存储地域。
准备 Key 与环境变量
- 在服务开通时确认实际 API 地址、模型 ID 与协议支持。文档中的 api.example.com 为示例域名。
- 妥善保管服务开通后取得的 Key,核对模型范围、有效期与额度;组织成员按自己的授权范围使用。
- 在本地终端设置以下变量,将示例地址与 Key 替换为真实接入信息。
export DAYWORLD_API_KEY="YOUR_DAYWORLD_API_KEY"
export DAYWORLD_BASE_URL="https://api.example.com/v1"
export DAYWORLD_MODEL="deepseek-flash"$env:DAYWORLD_API_KEY = "YOUR_DAYWORLD_API_KEY"
$env:DAYWORLD_BASE_URL = "https://api.example.com/v1"
$env:DAYWORLD_MODEL = "deepseek-flash"YOUR_DAYWORLD_API_KEY 是占位符,请在本地替换。OpenAI 格式使用 Authorization: Bearer;Messages 也可使用 x-api-key,并发送 anthropic-version: 2023-06-01。
模型名与权限
京东云提供算力支持,SLA 极高。实际可用性仍以当前模型供应和您约定的服务条款为准。先查询当前 Key 能使用的模型:
curl --fail-with-body --silent --show-error \
"$DAYWORLD_BASE_URL/models" \
-H "Authorization: Bearer $DAYWORLD_API_KEY"| 调用名 | 说明 |
|---|---|
deepseek-flash | 京东云 Flash;个人及采用该名称的企业账号使用。本文示例的默认值。 |
DeepSeek-V4.1-Flash-1017-b-jd | 部分企业账号目录中的京东云 Flash 名称。若目录返回此名称,请按目录填写。 |
deepseek-v4.1-flash-cyber-fq | FrontierQuest · DeepSeek Flash 网络安全版。需当前 Key 单独允许,价格与协议以自己的模型目录为准。 |
京东 Flash 的上述别名不区分字母大小写;新接入仍建议原样复制目录 ID。旧调用名 deepseek-v4.1-flash 兼容指向京东 Flash,不代表网络安全版。改名不会增加权限或变更账号价格。
只有报价、没有供应的模型不能调用。能看到价格不代表当前 Key 已获得权限;GET /v1/models 是当前 Key 的可用目录,不是全站所有模型。
第一次请求
先完成上面的环境变量设置。首次请求关闭思考,使用较小输出上限,便于确认鉴权和模型选择。每次实际模型请求都会按账号规则计费。
Python:python -m pip install --upgrade openai。Node.js:npm install openai,将代码保存为 quickstart.mjs 后运行 node quickstart.mjs。Windows PowerShell 使用对应选项卡,不能直接粘贴 Bash 的反斜杠续行语法。
curl --fail-with-body --silent --show-error \
"$DAYWORLD_BASE_URL/chat/completions" \
-H "Authorization: Bearer $DAYWORLD_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<JSON
{
"model": "$DAYWORLD_MODEL",
"messages": [{"role": "user", "content": "Explain an API in one short sentence."}],
"thinking": {"type": "disabled"},
"max_tokens": 256,
"stream": false
}
JSON$body = @{
model = $env:DAYWORLD_MODEL
messages = @(@{role="user"; content="Explain an API in one short sentence."})
thinking = @{type="disabled"}
max_tokens = 256
stream = $false
} | ConvertTo-Json -Depth 8
$request = @{
Method = "Post"
Uri = "$env:DAYWORLD_BASE_URL/chat/completions"
Headers = @{Authorization="Bearer $env:DAYWORLD_API_KEY"}
ContentType = "application/json"
Body = $body
}
$result = Invoke-RestMethod @request
$result.choices[0].message.contentimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DAYWORLD_API_KEY"],
base_url=os.environ["DAYWORLD_BASE_URL"],
timeout=90.0,
max_retries=0,
)
result = client.chat.completions.create(
model=os.environ["DAYWORLD_MODEL"],
messages=[{"role": "user", "content": "Explain an API in one short sentence."}],
max_tokens=256,
extra_body={"thinking": {"type": "disabled"}},
)
print(result.choices[0].message.content)
print(result.usage)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DAYWORLD_API_KEY,
baseURL: process.env.DAYWORLD_BASE_URL,
timeout: 90_000,
maxRetries: 0,
});
const result = await client.chat.completions.create({
model: process.env.DAYWORLD_MODEL,
messages: [{role: "user", content: "Explain an API in one short sentence."}],
thinking: {type: "disabled"},
max_tokens: 256,
});
console.log(result.choices[0].message.content);
console.log(result.usage);查看请求体与响应结构
{
"model": "deepseek-flash",
"messages": [
{
"role": "user",
"content": "Reply with OK."
}
],
"thinking": {
"type": "disabled"
},
"max_tokens": 256,
"stream": false
}{
"id": "example_completion",
"object": "chat.completion",
"model": "deepseek-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "OK"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 1,
"total_tokens": 13
}
}文本在 choices[0].message.content。同时检查 finish_reason:stop 为正常完成;length 说明预算或上下文限制截断;tool_calls 表示需要处理工具调用。不要把每个 HTTP 200 都当作完整答案。
流式输出(SSE)
设置 stream: true,逐块读取 choices[].delta.content,而不是等待完整 JSON。命令行 cURL 加 --no-buffer;反向代理也应关闭响应缓冲。
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["DAYWORLD_API_KEY"],
base_url=os.environ["DAYWORLD_BASE_URL"],
timeout=90.0, max_retries=0)
with client.chat.completions.create(
model=os.environ["DAYWORLD_MODEL"],
messages=[{"role": "user", "content": "Give three short tips for writing readable code."}],
stream=True,
stream_options={"include_usage": True},
max_tokens=512,
extra_body={"thinking": {"type": "disabled"}},
) as stream:
for chunk in stream:
if chunk.usage is not None:
print("\nUsage:", chunk.usage)
if not chunk.choices:
continue
text = chunk.choices[0].delta.content
if text:
print(text, end="", flush=True)
print()curl --no-buffer --fail-with-body --silent --show-error \
"$DAYWORLD_BASE_URL/chat/completions" \
-H "Authorization: Bearer $DAYWORLD_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<JSON
{"model":"$DAYWORLD_MODEL","messages":[{"role":"user","content":"Reply with OK."}],"stream":true,"max_tokens":256,"thinking":{"type":"disabled"}}
JSON- Chat SSE 使用
data:帧,正常结束标记为data: [DONE]。TCP 分段不是事件边界,请按 SSE 的空行分隔解析。 - 处理空
choices、仅用量帧和无文本增量。用量可能在终止块或额外块返回,取决于当前供应。 - 先输出思考内容时,
delta.content可能暂为空;思考内容在delta.reasoning_content。 - 输出中途断线不等于请求从未执行。已经收到部分结果后,不要无条件重发整个请求;重发是另一次调用。
思考模式
DeepSeek 官方通过 thinking 控制开关,并使用 reasoning_effort 选择思考强度。OpenAI Python SDK 的扩展参数要放进 extra_body。不同供应的模型版本可能存在差异;以下为当前官方参数写法,不代表每个历史模型均支持。
| 协议 | 关闭 | 开启与强度 |
|---|---|---|
| Chat Completions | thinking: {"type":"disabled"} | thinking: {"type":"enabled"}reasoning_effort: "low" | "high" | "max" |
| Responses | reasoning: {"effort":"none"} | reasoning: {"effort":"low" | "high" | "max"} |
| Messages | thinking: {"type":"disabled"} | thinking: {"type":"enabled"}output_config: {"effort":"low" | "high" | "max"} |
# Reuse the OpenAI client from the quickstart.
result = client.chat.completions.create(
model=os.environ["DAYWORLD_MODEL"],
messages=[{"role": "user", "content": "Check whether 23 times 17 equals 391."}],
reasoning_effort="high",
extra_body={"thinking": {"type": "enabled"}},
max_tokens=2048,
)
message = result.choices[0].message
print("Reasoning:", getattr(message, "reasoning_content", None))
print("Answer:", message.content)
print("Finish:", result.choices[0].finish_reason)思考内容与最终文本分开读取。开启思考不意味着设置 temperature 一定生效;不要依赖不支持的采样参数来改变推理行为。不要把官方默认值、最大上下文或最大输出预算直接套用于所有 DAYWORLD 渠道。
多轮对话与上下文
Chat Completions 不会凭上次响应 ID 自动记住历史。每轮发送需要的 messages,按 user → assistant → user 的顺序追加。限制历史长度,避免重复拼接整段会话。
# Reuse the OpenAI client from the quickstart.
history = [{"role": "user", "content": "Suggest a short name for a library."}]
first = client.chat.completions.create(
model=os.environ["DAYWORLD_MODEL"], messages=history,
max_tokens=256, extra_body={"thinking": {"type": "disabled"}},
)
history.append({"role": "assistant", "content": first.choices[0].message.content})
history.append({"role": "user", "content": "Explain why that name fits."})
second = client.chat.completions.create(
model=os.environ["DAYWORLD_MODEL"], messages=history,
max_tokens=256, extra_body={"thinking": {"type": "disabled"}},
)
print(second.choices[0].message.content)工具调用闭环
模型返回要调用的函数名和 JSON 参数;函数由您的应用执行,DAYWORLD 不会替您执行本地函数。完整闭环是:声明工具 → 读取 tool_calls → 校验并执行函数 → 带 tool_call_id 回传结果 → 请求最终回答。
展开完整 Python 示例:查询演示图书馆开放时间
import json
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["DAYWORLD_API_KEY"],
base_url=os.environ["DAYWORLD_BASE_URL"],
timeout=90.0, max_retries=0)
tools = [{
"type": "function",
"function": {
"name": "lookup_opening_hours",
"description": "Read the demo library opening hours for a weekday.",
"parameters": {
"type": "object",
"properties": {"day": {"type": "string", "enum": ["monday", "tuesday"]}},
"required": ["day"],
"additionalProperties": False,
},
},
}]
messages = [{"role": "user", "content": "Use the opening-hours tool for monday."}]
demo_hours = {"monday": "09:00-18:00", "tuesday": "09:00-18:00"}
for _ in range(3):
result = client.chat.completions.create(
model=os.environ["DAYWORLD_MODEL"], messages=messages,
tools=tools, max_tokens=512,
extra_body={"thinking": {"type": "disabled"}},
)
message = result.choices[0].message
if not message.tool_calls:
print(message.content)
break
# Preserve the complete assistant message, including tool call IDs.
messages.append(message.model_dump(exclude_none=True))
for call in message.tool_calls:
if call.function.name != "lookup_opening_hours":
raise ValueError("Unexpected tool name")
args = json.loads(call.function.arguments)
if set(args) != {"day"} or args["day"] not in demo_hours:
raise ValueError("Invalid tool arguments")
output = {"day": args["day"], "hours": demo_hours[args["day"]]}
messages.append({"role": "tool", "tool_call_id": call.id,
"content": json.dumps(output)})
else:
raise RuntimeError("Tool round limit reached")例子只查询固定演示数据,最多执行三轮。处理所有 tool_calls,并让每条 tool 结果对应原始调用 ID。不要执行模型返回的任意代码,也不要把参数字符串交给 eval。开启思考时,示例中的完整 assistant 消息保存方式仍需保留。
流式工具调用:先拼接参数,再解析
# Collect all fragments before parsing or executing a tool call.
calls = {}
for chunk in stream:
if not chunk.choices:
continue
for part in chunk.choices[0].delta.tool_calls or []:
item = calls.setdefault(part.index, {"id": "", "name": "", "arguments": ""})
if part.id:
item["id"] = part.id
if part.function:
item["name"] += part.function.name or ""
item["arguments"] += part.function.arguments or ""
# Validate the completed arguments and tool name against your allowlist next.流式 function.arguments 是字符串片段,不是每帧一份完整 JSON。按 index 拼接,等工具调用结束后再做 JSON 解析、函数白名单和参数校验。
JSON 输出
用 response_format: {"type":"json_object"} 请求 JSON,同时在提示词中明确写出 JSON 和预期格式。解析前检查是否为空、是否被 length 截断,再验证业务字段。合法 JSON 不等于符合业务 schema。
# Reuse the OpenAI client from the quickstart.
import json
result = client.chat.completions.create(
model=os.environ["DAYWORLD_MODEL"],
messages=[
{"role": "system", "content": 'Return JSON only, shaped like {"title":"...","tags":["..."]}.'},
{"role": "user", "content": "Summarize a guide about unit testing."},
],
response_format={"type": "json_object"},
max_tokens=512,
extra_body={"thinking": {"type": "disabled"}},
)
choice = result.choices[0]
if choice.finish_reason != "stop" or not (choice.message.content or "").strip():
raise ValueError("Incomplete or empty JSON response")
data = json.loads(choice.message.content)
if not isinstance(data, dict) or not isinstance(data.get("title"), str) or not isinstance(data.get("tags"), list):
raise ValueError("Unexpected application schema")
print(data)Responses 协议
当前京东 Flash 支持 POST /v1/responses。此协议使用 input、max_output_tokens 和 reasoning.effort,不能直接把 Chat 的 messages 请求体改一个 URL 后使用。
# Reuse the OpenAI client from the quickstart.
result = client.responses.create(
model=os.environ["DAYWORLD_MODEL"],
input=[{"role": "user", "content": "Explain an API in one short sentence."}],
reasoning={"effort": "none"},
max_output_tokens=256,
store=False,
)
print(result.output_text){
"model": "deepseek-flash",
"input": [
{
"role": "user",
"content": "Reply with OK."
}
],
"reasoning": {
"effort": "none"
},
"max_output_tokens": 256,
"store": false,
"stream": false
}# Reuse the OpenAI client from the quickstart.
with client.responses.create(
model=os.environ["DAYWORLD_MODEL"], input="Give three short study tips.",
reasoning={"effort": "none"}, max_output_tokens=512,
store=False, stream=True,
) as stream:
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
elif event.type in {"response.failed", "response.incomplete"}:
raise RuntimeError(f"Generation ended with {event.type}")
elif event.type == "response.completed":
print("\nUsage:", event.response.usage)Anthropic Messages 协议
这里调用的仍然是 DeepSeek。完整 HTTP 地址为 https://api.example.com/v1/messages;Anthropic SDK 的 Base URL 填 https://api.example.com。HTTP 示例和 SDK 示例使用同一个本站 Key 与模型 ID。
Python SDK:python -m pip install --upgrade anthropic。返回的 content 是内容块列表;流式使用 message_start、content_block_delta、message_stop 等事件,不要按 Chat 的 choices 结构解析。
curl --fail-with-body --silent --show-error \
"https://api.example.com/v1/messages" \
-H "x-api-key: $DAYWORLD_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
--data-binary @- <<JSON
{"model":"$DAYWORLD_MODEL","max_tokens":256,"thinking":{"type":"disabled"},"messages":[{"role":"user","content":"Reply with OK."}]}
JSONimport os
from anthropic import Anthropic
client = Anthropic(
api_key=os.environ["DAYWORLD_API_KEY"],
base_url="https://api.example.com",
timeout=90.0, max_retries=0,
)
result = client.messages.create(
model=os.environ["DAYWORLD_MODEL"],
max_tokens=256,
thinking={"type": "disabled"},
messages=[{"role": "user", "content": "Reply with OK."}],
)
print("".join(block.text for block in result.content if block.type == "text"))用量、缓存与价格
| 协议 | 常见字段 | 读取要点 |
|---|---|---|
| Chat | usage.prompt_tokensusage.completion_tokensusage.total_tokens | 读取最终请求用量,不要把流式中重复的累计值相加。 |
| Chat 缓存 | prompt_cache_hit_tokensprompt_cache_miss_tokens | 供应返回时分别表示缓存命中与未命中的输入;不要重复加到输入总数中。 |
| Responses | usage.input_tokensusage.output_tokens | 在完整响应或最终事件中读取;详细缓存与推理字段以实际响应为准。 |
| Messages | usage.input_tokensusage.output_tokens | 缓存读写字段可能独立返回,按 Messages 的用量定义解读。 |
DeepSeek 缓存匹配重复输入前缀,不保证每次命中。复用稳定的 system 提示词和相同上下文前缀有助于复用缓存,输出仍由模型生成。不要把缓存理解为固定答案缓存。
实际人民币单价、权限和计费规则以所开通服务的适用价格表及双方有效约定为准。DeepSeek 每天北京时间(UTC+8)09:00–12:00、14:00–18:00 为峰时,其余为谷时,暂不区分工作日、周末和节假日。本页不固定展示单价;此公开网站本身不处理计费。
错误处理与重试
先保存 HTTP 状态码、响应正文和响应头中的 X-Oneapi-Request-Id。流式请求还要保存最后一个事件及已收到的结果。向支持团队提供时间、线路域名、模型 ID 和请求 ID,隐去完整 Key 与敏感输入。
| 状态 | 先检查什么 | 如何处理 |
|---|---|---|
| 400 | JSON、必填字段、协议参数与上下文长度。 | 修正请求,勿原样循环重试。 |
| 401 | 本站 Key、Bearer/x-api-key 格式、过期和撤销状态。 | 更正鉴权,不在 URL 中传 Key。 |
| 402 / 403 | 响应说明中的余额、Key 白名单、组织成员额度或权限。 | 按实际错误处理;仅换模型拼写不能增加权限。 |
| 404 | 接口路径、重复 /v1、模型名与当前供应。 | 先查目录和协议,不猜测供应商地址。 |
| 429 | 响应的中文 message、rule、scope、limit、window_seconds 和 retry_after。 | 遵守 Retry-After,降低并发/RPM;上限为 0 时申请分配,等待本身不会增加额度。 |
| 500 / 502 / 503 / 504 | 上游失败、暂无可用渠道、网关或超时说明。 | 未收到输出时可有限退避重试;已收到部分输出先决定是否接受重复调用。 |
重试应有次数上限、指数退避和少量随机抖动,优先尊重 Retry-After。SDK 可能自带重试;本文示例用 max_retries=0(Node.js 为 maxRetries: 0)避免首轮调试时隐藏重复调用。不要将 DeepSeek 直连服务的限流承诺套用到本站账号或组织。
额度与功能边界
- 组织共享余额、个人余额、成员消费上限、Key 配额是不同限制。管理员为成员分配上限不等于给成员另建一份独立现金余额。请在组织页面和账单中核对实际资金来源。
- 三个原生协议的请求结构和 SSE 结束事件不同。当前京东 Flash 已接入 Chat Completions、Responses、Messages;网络安全版或其他历史型号只使用目录明确支持的协议。
- 官方文档中的 Files、搜索、Vision、FIM、Beta strict 等能力不因协议兼容就自动在本站开放。本页暂不提供这些未经逐项确认的接入示例。
- 不要在模型名后自行追加 -thinking、-high 等后缀。需要思考时使用本页参数,模型名保持为账号目录中的 ID。
请求字段速查
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 当前 Key 目录中的模型 ID。 |
messages | array | 是 | 至少一条消息;每条含 role 和对应 content,工具消息还需 tool_call_id。 |
stream | boolean | 否 | 默认 false;true 返回 SSE。 |
max_tokens | integer | 否 | 正整数。有效上限取决于实际模型版本、上下文和思考预算。 |
thinking | object | 否 | type 为 enabled 或 disabled;Python SDK 放入 extra_body。 |
tools | array | 否 | 声明 function 工具。需由应用处理返回的 tool_calls。 |
| 用途 | Chat Completions | Responses | Messages |
|---|---|---|---|
| 模型 | model | model | model |
| 输入 | messages | input | messages |
| 系统指令 | messages[]: role=system | instructions | system |
| 输出上限 | max_tokens | max_output_tokens | max_tokens |
| 流式开关 | stream | stream | stream |
| 函数工具 | tools[].function | tools[]: type=function | tools[].input_schema |
| 最终文本 | choices[0].message.content | output[].content[] / SDK output_text | content[]: type=text |
只对确有需要的参数赋值。先用最小请求跑通,再逐项添加思考、工具或输出格式,便于定位兼容性问题。本文范围暂限 DeepSeek。
官方参考与本站规则
- DeepSeek:首次调用 API
- Chat Completions 字段定义
- 思考模式 · Tool Calls · JSON Output
- Responses API · Anthropic API · 上下文缓存
官方资料用于解释原生协议;本站的地址、模型 ID、Key 权限、实际供应和人民币价格以 DAYWORLD 当前账号目录与账单为准。文档核对日期:2026-11-10。