TokenPilotAPI 文件
English简体中文繁體中文
控制台 ↗
API 文件快速開始

快速開始

向可用模型發出你的第一個請求。

在控制台建立金鑰,在本機設定 TOKENPILOT_API_KEY,再查詢該金鑰可使用的模型。將範例中的 REPLACE_WITH_MODEL_ID 換成回應中的模型 ID。

建立 API Key

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 openai
import 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)