JuCode 文档

快速开始

五分钟内发出第一个请求。

拿到 API Key

注册并登录

访问 jucode.cn 注册账号。

创建 API Key

在控制台的 API Keys 页面创建一个新 Key。它形如 sk-juc- 加 43 位字符,总长 50 位。

完整 Key 只在创建时显示一次

之后列表里只能看到前缀。请立刻存进你的密钥管理工具或环境变量,别让它进版本库。

存进环境变量

export JUCODE_API_KEY="sk-juc-..."

第一个请求

curl https://api.jucode.cn/v1/chat/completions \
  -H "Authorization: Bearer $JUCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "messages": [
      {"role": "user", "content": "用一句话解释什么是幂等性"}
    ]
  }'

如果返回 model_not_found,说明这个模型名在你的账号下不可用。先查一下有哪些能用:

curl https://api.jucode.cn/v1/models \
  -H "Authorization: Bearer $JUCODE_API_KEY"

用 SDK

pip install openai
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["JUCODE_API_KEY"],
    base_url="https://api.jucode.cn/v1",
)

resp = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "用一句话解释什么是幂等性"}],
)
print(resp.choices[0].message.content)

流式输出

stream = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "写一首关于秋天的短诗"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

流式响应末尾总有一个用量帧

网关会自动注入 stream_options.include_usage = true,所以流的最后一帧带 usagechoices 为空数组。上面的 if chunk.choices 判断就是为了跳过它——如果你的代码 直接取 chunk.choices[0],这一帧会让它抛 IndexError

这个注入无法关闭,它是准确计费的前提。

下一步

On this page