> ## 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 に変更する

> base URL を https://api.cometapi.com/v1 に設定して、OpenAI 互換クライアントまたは直接の HTTP リクエストを CometAPI にルーティングします。

OpenAI 互換の SDK またはエンドポイントを使用する場合は、base URL を `https://api.cometapi.com/v1` に変更してください。API リファレンスのエンドポイントパスとリクエスト本文の形式はそのまま使い、CometAPI API キーを使用します。

## 正しい base URL を使う

OpenAI 互換の base URL は次のとおりです。

```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 の例では、CometAPI の base URL を設定しています。

```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`                        | OpenAI 互換エンドポイント用の base URL に `/v1` を含めてください。                            |
| JSON ではなく HTML               | HTTP クライアントが誤ったパスからのリダイレクトに従っていないか確認してください。                              |
| `401`                        | `Authorization: Bearer $COMETAPI_KEY` を使用してください。                         |
| Management API auth mismatch | API キー管理エンドポイントでは、Bearer による model-request auth ではなく、個人用アクセストークン値を使用します。 |

## 関連リンク

* [CometAPI クイックスタート](/ja/overview/quick-start)
* [重要なガイドライン](/ja/overview/important-guidelines)
* [エラーコードと対処](/ja/errors/error-codes-handling)
* [Models ページ](/ja/overview/models)
* [Model directory](https://www.cometapi.com/models/)
* [Pricing](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": "CometAPI に base URL を変更するにはどうすればよいですか？",
        "description": "base URL を https://api.cometapi.com/v1 に設定して、OpenAI 互換クライアントまたは直接の HTTP リクエストを CometAPI に変更します。",
        "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": "CometAPI に base URL を変更するにはどうすればよいですか？",
            "item": "https://apidoc.cometapi.com/guides/change-base-url-to-cometapi"
          }
        ]
      }
    ]
    }
    `}
</script>
