Quick Start
此内容尚不支持你的语言。
This section will guide you to complete a minimal viable integration of UURoute in a few minutes.
Using API directly
Section titled “Using API directly”import requestsimport json
response = requests.post( url="https://api.uuroute.ai/v1/chat/completions", headers={ "Authorization": "Bearer <UUROUTE_API_KEY>", "HTTP-Referer": "<YOUR_SITE_URL>", # Optional. Site URL for rankings on uuroute.ai. "X-Title": "<YOUR_SITE_NAME>", # Optional. Site title for rankings on uuroute.ai. }, data=json.dumps({ "model": "gpt-4o-mini", # Optional "messages": [ { "role": "user", "content": "What is the meaning of life?" } ] }))fetch('https://api.uuroute.ai/v1/chat/completions', { method: 'POST', headers: { Authorization: 'Bearer <UUROUTE_API_KEY>', 'HTTP-Referer': '<YOUR_SITE_URL>', // Optional. Site URL for rankings on uuroute.ai. 'X-Title': '<YOUR_SITE_NAME>', // Optional. Site title for rankings on uuroute.ai. 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'gpt-4o-mini', messages: [ { role: 'user', content: 'What is the meaning of life?', }, ], }),});curl https://api.uuroute.ai/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $UUROUTE_API_KEY" \ -d '{ "model": "gpt-4o-mini", "messages": [ { "role": "user", "content": "What is the meaning of life?" } ]}'Using the OpenAI SDK
Section titled “Using the OpenAI SDK”You can also use any OpenAI-compatible client by setting the UURoute API base URL.
import OpenAI from 'openai';
const openai = new OpenAI({ baseURL: 'https://api.uuroute.ai/v1', apiKey: '<UUROUTE_API_KEY>', defaultHeaders: { 'HTTP-Referer': '<YOUR_SITE_URL>', // Optional. Site URL for rankings on uuroute.ai. 'X-Title': '<YOUR_SITE_NAME>', // Optional. Site title for rankings on uuroute.ai. },});
async function main() { const completion = await openai.chat.completions.create({ model: 'gpt-4o-mini', messages: [ { role: 'user', content: 'What is the meaning of life?', }, ], });
console.log(completion.choices[0].message);}
main();from openai import OpenAI
client = OpenAI( base_url="https://api.uuroute.ai/v1", api_key="<UUROUTE_API_KEY>",)
completion = client.chat.completions.create( extra_headers={ "HTTP-Referer": "<YOUR_SITE_URL>", # Optional. Site URL for rankings on uuroute.ai. "X-Title": "<YOUR_SITE_NAME>", # Optional. Site title for rankings on uuroute.ai. }, model="gpt-4o-mini", messages=[ { "role": "user", "content": "What is the meaning of life?" } ])
print(completion.choices[0].message.content)The API also supports streaming.