Developer guide
Authenticate with an API key
The header containing the API key and the base URL to set in the SDK
The CLEVI Gateway authenticates both OpenAI-compatible and Anthropic-compatible paths with a single API key.
The client needs two values: the authentication header containing the key and the SDK's base URL. The accepted header formats and base URLs differ by specification.
After completing the setup, you can immediately verify authentication by retrieving the model list.
A 401 is returned when authentication fails, while a 403 is returned when the request passes authentication but does not meet permission or quota requirements.
Issue an API key from the API Keys page in the console. You can also revoke keys and manage their usage scope on the same page.
Authentication header
Both specifications include the API key in a single request header. Use either the X-API-Key header or the Authorization header; the accepted format differs by specification.
| Header | OpenAI-compatible | Anthropic-compatible |
|---|---|---|
| X-API-Key: <키> | Supported | Supported |
| Authorization: Bearer <키> | Supported | Supported |
| Authorization: <키> (without Bearer) | Rejected | Supported |
The Bearer prefix is required when using the Authorization header with the OpenAI-compatible path. If you send only the key without the prefix, the gateway rejects the request.
Header names are case-insensitive, so the x-api-key header sent by the Anthropic SDK also works as is. If both headers are specified, the X-API-Key value takes precedence.
base URL
Existing SDKs can continue to be used by changing only the base URL to one of the addresses below. The two addresses differ in whether they include /v1, so specify the address that matches the relevant specification exactly.
| Specification | base URL | Path rule |
|---|---|---|
| OpenAI-compatible | https://platform.clevi.net/api/v2/aiservice/openai/v1 | Include /v1 in the base URL. |
| Anthropic-compatible | https://platform.clevi.net/api/v2/aiservice/anthropic | The Anthropic SDK adds /v1 directly to the request path, so the URL ends before /v1. |
Verify authentication
After setting the key and base URL, you can verify authentication by retrieving the model list. The examples below perform the same request using curl, the OpenAI SDK, and the Anthropic SDK. In place of sk-..., enter the key issued on the API key page.
When retrieving the list with curl, specify the full path up to /v1/models for both specifications. The first command uses the X-API-Key header for the OpenAI-compatible path, while the second command uses the Authorization header for the Anthropic-compatible path.
curl https://platform.clevi.net/api/v2/aiservice/openai/v1/models \
-H "X-API-Key: sk-..."
curl https://platform.clevi.net/api/v2/aiservice/anthropic/v1/models \
-H "Authorization: Bearer sk-..." \
-H "anthropic-version: 2023-06-01"For the OpenAI SDK, specify a URL that includes /v1 in base_url.
from openai import OpenAI
client = OpenAI(
api_key="sk-...",
base_url="https://platform.clevi.net/api/v2/aiservice/openai/v1",
)
for model in client.models.list():
print(model.id)For the Anthropic SDK, specify a URL in base_url that ends before /v1.
For authentication, use the x-api-key header sent by the SDK as is.
from anthropic import Anthropic
client = Anthropic(
api_key="sk-...",
base_url="https://platform.clevi.net/api/v2/aiservice/anthropic",
)
for model in client.models.list(limit=20).data:
print(model.id)For any example, a 200 response means that authentication was successful, and the response's data contains the list of models that can be called with this key. If you receive a 401, check the cause in the order described in the next section.
Authentication failure
If you send a missing, expired, or revoked key, a 401 is returned. When you make a request without a key through the OpenAI-compatible path, the body below is returned; through the Anthropic-compatible path, error.type is authentication_error.
{
"error": {
"message": "API key is required.",
"type": "invalid_request_error"
}
}If you receive a 401, check the following in order.
- Check the key status on the API key page. If the key has expired or been revoked, issue a new one.
- Check whether the header name is X-API-Key or Authorization.
- If you are using the Authorization header on the OpenAI-compatible path, check whether it has the Bearer prefix.
After making the changes, run the model list request in the authentication verification section again and confirm that you receive a 200 response.
Headers used together
All of the following headers are optional. We recommend specifying X-Request-Id to help track issues.
| Header | Purpose | If omitted |
|---|---|---|
| X-Request-Id | Identifier for tracking the request. The Anthropic-compatible route returns the same value in the response's request-id header. | Issued by the server. |
| X-Region-Code | Specifies the region for the call. | It is global. |
| X-Product-Sku (can also be specified with the product_sku query parameter) | Directly specifies the Product SKU to be used for billing. The header takes precedence over the query parameter and is mainly used for voice routes. | It cannot be omitted for voice routes. audio/speech and audio/transcriptions select the Product using model in the request body. |
| anthropic-version / anthropic-beta | Passed through unchanged on the Anthropic-compatible route. | The version is 2023-06-01. |
If 5xx errors recur, let us know through the Help and Contact options, along with the X-Request-Id. If you specified the value directly, it can be compared immediately with the client logs.