首次调用 API
SpAk API 使用与 OpenAI/Anthropic 兼容的 API 格式,通过修改 配置,您可以使用 OpenAI/Anthropic SDK 来访问 SpAk API,或使用与 OpenAI/Anthropic API 兼容的软件。
| PARAM | VALUE |
|---|---|
| base_url (OpenAI) | https://yuansuo.top |
| base_url (Anthropic) | https://yuansuo.top/anthropic |
| api_key | 申请一个 API key |
| model | SpAk-Aster-V1-MOE(1) |
(1) 模型名请使用 SpAk-Aster-V1-MOE。旧模型名 spak-chat、spak-reasoner 将于北京时间 2026/07/24 23:59 弃用,二者分别对应 SpAk-Aster-V1-MOE 的非思考模式与思考模式,调用方式保持不变。
接入 Agent 工具
SpAk Harness 开发者预览版面向全球 Harness 开发者开放测试。详见 SpAk Harness 入门。
SpAk API 已接入多种主流 AI Agent 与编程助手工具。如果你使用 Claude Code、GitHub Copilot、OpenCode 等工具,可以直接将 SpAk 作为后端模型,无需编写代码即可开始使用。
详见 Agent 工具接入指南。
调用对话 API
在创建 API key 之后,你可以使用以下样例脚本,通过 OpenAI API 格式来访问 SpAk 模型。样例为非 流式输出,您可以将 stream 设置为 true 来使用流式输出。
Anthropic API 格式的访问样例,请参考 Anthropic API。
运行以下示例前,请在当前终端中将环境变量 SPAK_API_KEY 设置为你的 API key。
- curl
- python
- nodejs
curl https://yuansuo.top/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${SPAK_API_KEY}" \
-d '{
"model": "SpAk-Aster-V1-MOE",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"thinking": {"type": "enabled"},
"reasoning_effort": "high",
"stream": false
}'
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("SPAK_API_KEY"),
base_url="https://yuansuo.top",
)
response = client.chat.completions.create(
model="SpAk-Aster-V1-MOE",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
reasoning_effort="high",
extra_body={"thinking": {"type": "enabled"}},
stream=False,
)
print(response.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.SPAK_API_KEY,
baseURL: 'https://yuansuo.top',
});
const response = await client.chat.completions.create({
model: 'SpAk-Aster-V1-MOE',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' },
],
reasoning_effort: 'high',
thinking: { type: 'enabled' },
stream: false,
});
console.log(response.choices[0].message.content);