SDK 示例
TokenMark 兼容 OpenAI SDK。只需把 base_url / baseURL 指向 https://tokenmark.org/v1,api_key 换成你的 sk- 密钥。
curl
curl https://tokenmark.org/v1/chat/completions \
-H "Authorization: Bearer sk-你的密钥" \
-H "Content-Type: application/json" \
-d '{"model": "chat", "messages": [{"role": "user", "content": "你好"}]}'
Python(openai 官方 SDK)
from openai import OpenAI
client = OpenAI(
base_url="https://tokenmark.org/v1",
api_key="sk-你的密钥",
)
# 非流式
resp = client.chat.completions.create(
model="chat",
messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)
# 流式
stream = client.chat.completions.create(
model="chat",
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)
Node.js(openai 官方 SDK)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://tokenmark.org/v1",
apiKey: "sk-你的密钥",
});
const resp = await client.chat.completions.create({
model: "chat",
messages: [{ role: "user", content: "你好" }],
});
console.log(resp.choices[0].message.content);
通用 OpenAI 兼容客户端
任意支持自定义 Base URL 的客户端均可接入:
| 客户端 | Base URL 填写 |
|---|---|
| NextChat (ChatGPT-Next-Web) | https://tokenmark.org/v1 |
| Cherry Studio | https://tokenmark.org/v1 |
| LangChain(OpenAI 兼容) | https://tokenmark.org/v1 |
| LiteLLM | https://tokenmark.org/v1 |
获取可用模型
curl https://tokenmark.org/v1/models \
-H "Authorization: Bearer sk-你的密钥"
返回的模型 ID 直接填入 model 参数。不同账户等级(免费版/标准版/VIP/企业版)可用的模型范围不同,超出范围的模型返回校验错误。