在控制台创建密钥,在本地设置 TOKENPILOT_API_KEY,再查询该密钥可访问的模型。将示例中的 REPLACE_WITH_MODEL_ID 换成响应中的模型 ID。
1. 设置 API Key
export TOKENPILOT_API_KEY='replace-with-your-key' # bash / zsh
# PowerShell: $env:TOKENPILOT_API_KEY = 'replace-with-your-key'2. 查询可用模型
curl "https://api.tokentpilot.com/v1/models" \
-H "Authorization: Bearer $TOKENPILOT_API_KEY"3. 发出首个请求
curl "https://api.tokentpilot.com/v1/chat/completions" \
-H "Authorization: Bearer $TOKENPILOT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"REPLACE_WITH_MODEL_ID","messages":[{"role":"user","content":"Reply in one sentence."}]}'Python SDK
python -m pip install openaiimport os
from openai import OpenAI
client = OpenAI(
base_url="https://api.tokentpilot.com/v1",
api_key=os.environ["TOKENPILOT_API_KEY"],
)
reply = client.chat.completions.create(
model="REPLACE_WITH_MODEL_ID",
messages=[{"role": "user", "content": "Say hello."}],
)
print(reply.choices[0].message.content)