入门指南
本指南将带您完成 GreatRouter API 的首次推理。
1. 获取 API 密钥
在 GreatRouter 控制面板 注册以获取 API 密钥。每个新账户均包含免费额度。
设置环境变量:
export GREAT_ROUTER_API_KEY="pk_live_..."2. 发起第一个请求
GreatRouter 使用 /v1/auto/route 端点进行提示的自动路由。发送您的提示和模型输入;路由器将选择最佳模型。
使用 curl
curl https://api.greatrouterai.com/v1/auto/route \ -H "Authorization: Bearer $GREAT_ROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "prompt": "法国的首都是什么?", "input": { "messages": [{"role": "user", "content": "法国的首都是什么?"}] } }'使用 Python
import requests
response = requests.post( "https://api.greatrouterai.com/v1/auto/route", headers={ "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", }, json={ "prompt": "法国的首都是什么?", "input": { "messages": [{"role": "user", "content": "法国的首都是什么?"}] }, },)
result = response.json()print(result["result"]["choices"][0]["message"]["content"])使用 Node.js
const response = await fetch('https://api.greatrouterai.com/v1/auto/route', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.GREAT_ROUTER_API_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ prompt: '法国的首都是什么?', input: { messages: [{ role: 'user', content: '法国的首都是什么?' }], }, }),});
const result = await response.json();console.log(result.result.choices[0].message.content);3. 直接指定模型
如果您希望使用特定模型而非自动路由,请使用 /v1/models/route 并指定查询:
curl https://api.greatrouterai.com/v1/models/route \ -H "Authorization: Bearer $GREAT_ROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "text_generation", "input": { "model": "meta/llama-3.3-70b-instruct-fp8-fast", "messages": [{"role": "user", "content": "用三句话解释量子计算。"}] } }'模型 ID 使用 提供商/模型名称 格式。在模型页面浏览所有模型。