> ## 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.

# CometAPI'yi OpenAI SDK'leri ile kullanma

> CometAPI API anahtarını ve base URL'yi ayarlayarak OpenAI Python ve Node.js SDK'lerini CometAPI için yapılandırın.

İstemcideki iki ayarı değiştirerek OpenAI SDK'yi CometAPI ile kullanın: API anahtarı ve base URL. Mevcut OpenAI uyumlu istek kodunuzu koruyun, ardından model ID'yi kullanılabilir bir CometAPI model ID ile değiştirin.

## SDK'yi yükleme

Aşağıdaki komut OpenAI Python SDK'yi yükler:

```bash theme={null}
pip install openai
```

Aşağıdaki komut OpenAI Node.js SDK'yi yükler:

```bash theme={null}
npm install openai
```

## Python istemcisi

Aşağıdaki Python örneği bir CometAPI istemcisi oluşturur ve bir sohbet isteği gönderir:

```python theme={null}
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:

```json theme={null}
{
  "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:

```javascript theme={null}
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:

```json theme={null}
{
  "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ğişkeninin 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'te `baseURL` ayarlayın.                                   |
| Geçersiz model ID            | [Models page](/tr/overview/models) içinden bir model ID seçin.                              |
| Eksik `/v1`                  | OpenAI uyumlu SDK'ler için `https://api.cometapi.com/v1` kullanın.                          |

## İlgili bağlantılar

* [CometAPI hızlı başlangıç](/tr/overview/quick-start)
* [Chat Completions](/api/text/chat)
* [Responses](/api/text/responses)
* [Models sayfası](/tr/overview/models)
* [Model dizini](https://www.cometapi.com/models/)
* [Fiyatlandırma](https://www.cometapi.com/pricing/)
* [OpenAI Python SDK](https://github.com/openai/openai-python)
* [OpenAI Node.js SDK](https://github.com/openai/openai-node)

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "TechArticle",
        "@id": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk",
        "headline": "CometAPI'yi OpenAI SDK ile nasıl kullanırım?",
        "description": "CometAPI API anahtarını ve base URL'i ayarlayarak CometAPI'yi OpenAI Python ve Node.js SDK'leri ile kullanın.",
        "url": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk",
        "author": {
          "@type": "Organization",
          "name": "CometAPI"
        },
        "publisher": {
          "@type": "Organization",
          "name": "CometAPI",
          "url": "https://www.cometapi.com"
        }
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "CometAPI Dokümantasyonu",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Kılavuzlar",
            "item": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "CometAPI'yi OpenAI SDK ile nasıl kullanırım?",
            "item": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk"
          }
        ]
      }
    ]
    }
    `}
</script>
