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

# Change the base URL to CometAPI

> Route an OpenAI-compatible client or direct HTTP request to CometAPI by setting the base URL to https://api.cometapi.com/v1.

Change the base URL to `https://api.cometapi.com/v1` when you use OpenAI-compatible SDKs or endpoints. Keep the endpoint path and request body format from the API reference, then use your CometAPI API key.

## Use the correct base URL

The OpenAI-compatible base URL is:

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

## Python base URL

The following Python example changes only the client configuration:

```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

The following Node.js example sets the 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",
});
```

## Test the change

The following request verifies that the base URL and API key work:

```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."
      }
    ]
  }'
```

A successful response returns a chat completion object:

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

## Common errors

| Error                        | Fix                                                                                      |
| ---------------------------- | ---------------------------------------------------------------------------------------- |
| `404`                        | Include `/v1` in the base URL for OpenAI-compatible endpoints.                           |
| HTML instead of JSON         | Check whether your HTTP client followed a redirect from a wrong path.                    |
| `401`                        | Use `Authorization: Bearer $COMETAPI_KEY`.                                               |
| Management API auth mismatch | API key management endpoints use a personal access value, not bearer model-request auth. |

## Related links

* [CometAPI quickstart](/overview/quick-start)
* [Important guidelines](/overview/important-guidelines)
* [Error Codes & Handling](/errors/error-codes-handling)
* [Models page](/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": "How do I change the base URL to CometAPI?",
        "description": "Change an OpenAI-compatible client or direct HTTP request to CometAPI by setting the base URL to 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 Docs",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Guides",
            "item": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "How do I change the base URL to CometAPI?",
            "item": "https://apidoc.cometapi.com/guides/change-base-url-to-cometapi"
          }
        ]
      }
    ]
    }
    `}
</script>
