Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
OpenAI SDK’yı CometAPI ile kullanmak için iki istemci ayarını değiştirin: API anahtarı ve base URL. Mevcut OpenAI uyumlu istek kodunuzu koruyun, ardından model ID değerini kullanılabilir bir CometAPI model ID ile değiştirin.
SDK’yı yükleyin
Aşağıdaki komut OpenAI Python SDK’sını yükler:
Aşağıdaki komut OpenAI Node.js SDK’sını yükler:
Python istemcisi
Aşağıdaki Python örneği bir CometAPI istemcisi oluşturur ve bir chat isteği gönderir:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["COMETAPI_KEY"],
base_url="https://api.cometapi.com/v1",
)
completion = client.chat.completions.create(
model="your-model-id",
messages=[
{
"role": "user",
"content": "Answer in one short sentence: What is CometAPI?",
}
],
)
print(completion.choices[0].message.content)
Yanıt nesnesi assistant mesajını içerir:
{
"choices": [
{
"message": {
"role": "assistant",
"content": "CometAPI provides API access to models from multiple providers."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 16,
"completion_tokens": 12,
"total_tokens": 28
}
}
Node.js istemcisi
Aşağıdaki Node.js örneği OpenAI SDK ile baseURL kullanır:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.COMETAPI_KEY,
baseURL: "https://api.cometapi.com/v1",
});
const completion = await client.chat.completions.create({
model: "your-model-id",
messages: [
{
role: "user",
content: "Answer in one short sentence: What is CometAPI?",
},
],
});
console.log(completion.choices[0].message.content);
Yanıt yapısı, OpenAI uyumlu aynı chat completion yapısıdır:
{
"id": "chatcmpl_example",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "CometAPI provides API access to models from multiple providers."
}
}
]
}
Yaygın hatalar
| Hata | Düzeltme |
|---|
401 | COMETAPI_KEY değerinin ayarlandığını ve isteğin Bearer auth kullandığını doğrulayın. |
| SDK hâlâ OpenAI’yi çağırıyor | Python’da base_url veya Node.js’de baseURL ayarlayın. |
| Geçersiz model ID | Model sayfası içinden bir model ID seçin. |
Eksik /v1 | OpenAI uyumlu SDK’lar için https://api.cometapi.com/v1 kullanın. |
İlgili bağlantılar