Developer guide
Authenticate with an API key
The header containing the API key and the base URL to configure in the SDK
The CLEVI gateway authenticates both the OpenAI-compatible path and the Anthropic-compatible path with a single API key.
There are two values to configure on the client: the authentication header containing the key and the SDK's base URL. The accepted header format and base URL differ by specification.
After completing the configuration, retrieve the model list to immediately verify whether authentication is working.
A 401 is returned when authentication fails, and a 403 is returned when authorization or quota conditions are not met after authentication succeeds.
Issue an API key from the API Keys screen in the console. You can also revoke the key and manage its usage scope on the same screen.
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: <키> | Accepted | Accepted |
| Authorization: Bearer <키> | Accepted | Accepted |
| Authorization: <키> (without Bearer) | Rejected | Accepted |
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 the address below. The two addresses differ in whether they include /v1, so specify the address that matches the specification exactly.
| Specification | base URL | Path rules |
|---|---|---|
| OpenAI-compatible | https://platform.clevi.net/api/v2/aiservice/openai/v1 | Include up to /v1 in the base URL. |
| Anthropic-compatible | https://platform.clevi.net/api/v2/aiservice/anthropic | It ends before /v1 because the Anthropic SDK adds /v1 directly to the request path. |
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. Replace sk-... with the key issued on the API key page.
When retrieving the list with curl, specify the full path up to /v1/models for both formats. The first command uses the X-API-Key header with the OpenAI-compatible path, while the second uses the Authorization header with 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)If any example returns 200, authentication was successful, and the response's data contains the list of models that can be called with this key. If it returns 401, check the cause in the order described in the next section.
Authentication failure
If you send a missing, expired, or revoked key, 401 is returned. If you make a call 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 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 with the OpenAI-compatible path, check whether it has the Bearer prefix.
After making the corrections, run the model list request in the authentication verification section again and confirm that it returns 200.
Headers used together
All of the following headers are optional. We recommend specifying X-Request-Id so that issues can be tracked.
| Header | Purpose | If omitted |
|---|---|---|
| X-Request-Id | An identifier for tracking requests. 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 request. | It is global. |
| X-Product-Sku (can also be specified with the query parameter product_sku) | Directly specifies the Product SKU to use for billing. The header takes precedence over the query parameter and is primarily used for voice and speech 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, please let us know through Help and Contact Us, along with the X-Request-Id. If you specified the value directly, it can be immediately compared with the client records.