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

# غيّر base URL إلى CometAPI

> وجّه عميلًا متوافقًا مع OpenAI أو طلب HTTP مباشرًا إلى CometAPI من خلال تعيين base URL إلى https://api.cometapi.com/v1.

غيّر base URL إلى `https://api.cometapi.com/v1` عند استخدام SDKs أو endpoints المتوافقة مع OpenAI. احتفِظ بمسار endpoint وتنسيق جسم الطلب من مرجع API، ثم استخدم مفتاح CometAPI API الخاص بك.

## استخدم base URL الصحيح

Base URL المتوافق مع OpenAI هو:

```text theme={null}
https://api.cometapi.com/v1
```

## Python base URL

يغيّر مثال Python التالي إعدادات العميل فقط:

```python theme={null}
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["COMETAPI_KEY"],
    base_url="https://api.cometapi.com/v1",
)
```

## Node.js base URL

يضبط مثال Node.js التالي base URL الخاص بـ CometAPI:

```javascript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.COMETAPI_KEY,
  baseURL: "https://api.cometapi.com/v1",
});
```

## اختبر التغيير

يتحقق الطلب التالي من أن base URL ومفتاح API يعملان:

```bash theme={null}
curl https://api.cometapi.com/v1/chat/completions \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "messages": [
      {
        "role": "user",
        "content": "Say hello in one sentence."
      }
    ]
  }'
```

تعيد الاستجابة الناجحة كائن إكمال محادثة:

```json theme={null}
{
  "object": "chat.completion",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Hello from CometAPI."
      }
    }
  ]
}
```

## الأخطاء الشائعة

| الخطأ                           | الحل                                                                               |
| ------------------------------- | ---------------------------------------------------------------------------------- |
| `404`                           | أدرِج `/v1` في base URL الخاص بـ endpoints المتوافقة مع OpenAI.                    |
| HTML بدلًا من JSON              | تحقّق مما إذا كان عميل HTTP لديك قد اتّبع إعادة توجيه من مسار خاطئ.                |
| `401`                           | استخدم `Authorization: Bearer $COMETAPI_KEY`.                                      |
| عدم تطابق مصادقة Management API | تستخدم endpoints إدارة مفاتيح API قيمة وصول شخصية، وليس bearer model-request auth. |

## روابط ذات صلة

* [البدء السريع لـ CometAPI](/ar/overview/quick-start)
* [إرشادات مهمة](/ar/overview/important-guidelines)
* [رموز الأخطاء ومعالجتها](/ar/errors/error-codes-handling)
* [صفحة النماذج](/ar/overview/models)
* [دليل النماذج](https://www.cometapi.com/models/)
* [الأسعار](https://www.cometapi.com/pricing/)

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "TechArticle",
        "@id": "https://apidoc.cometapi.com/guides/change-base-url-to-cometapi",
        "headline": "كيف أغيّر base URL إلى CometAPI؟",
        "description": "غيّر عميلًا متوافقًا مع OpenAI أو طلب HTTP مباشرًا إلى CometAPI من خلال تعيين base URL إلى https://api.cometapi.com/v1.",
        "url": "https://apidoc.cometapi.com/guides/change-base-url-to-cometapi",
        "author": {
          "@type": "Organization",
          "name": "CometAPI"
        },
        "publisher": {
          "@type": "Organization",
          "name": "CometAPI",
          "url": "https://www.cometapi.com"
        }
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "مستندات CometAPI",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "الأدلة",
            "item": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "كيف أغيّر base URL إلى CometAPI؟",
            "item": "https://apidoc.cometapi.com/guides/change-base-url-to-cometapi"
          }
        ]
      }
    ]
    }
    `}
</script>
