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 the OpenAI-compatible and Anthropic-compatible paths 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 permitted header format and base URL differ by specification.
After completing the configuration, you can immediately verify authentication by retrieving the model list.
If authentication fails, 401 is returned. If authorisation or quota requirements are not met after authentication succeeds, 403 is returned.

Issue an API key from the API Keys page in the console. You can also revoke keys and manage their scope of use 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 permitted format differs by specification.

HeaderOpenAI-compatibleAnthropic-compatible
X-API-Key: <키>AcceptedAccepted
Authorization: Bearer <키>AcceptedAccepted
Authorization: <키> (without Bearer)RejectedAccepted

The Authorization header requires the Bearer prefix on the OpenAI-compatible path. If you send only the key without the prefix, the gateway rejects the request.

Header names are not case-sensitive, 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 specification exactly.

Specificationbase URLPath rules
OpenAI-compatiblehttps://platform.clevi.net/api/v2/aiservice/openai/v1Include up to /v1 in the base URL.
Anthropic-compatiblehttps://platform.clevi.net/api/v2/aiservice/anthropicThe Anthropic SDK adds /v1 directly to the request path, so the base 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. Replace sk-... with the key issued on the API key screen.

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 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 following section.

Authentication failure

If you send a missing, expired or revoked key, a 401 is returned. When calling the OpenAI-compatible path without a key, the response body below is returned; for 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.

  1. Check the key status on the API key screen. If the key has expired or been revoked, issue a new one.
  2. Check whether the header name is X-API-Key or Authorization.
  3. If you are using the Authorization header with 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 so that issues can be tracked.

HeaderPurposeIf omitted
X-Request-IdIdentifier for tracking requests. The Anthropic-compatible route returns the same value in the request-id response header.Issued by the server.
X-Region-CodeSpecifies the region for the request.It is global.
X-Product-Sku (can also be specified with the product_sku query parameter)Directly specifies the Product SKU to use for billing. The header takes precedence over the query parameter and is mainly 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-betaPassed through unchanged on the Anthropic-compatible route.The version is 2023-06-01.

If 5xx errors occur repeatedly, please let us know via Help and Contact, together with the X-Request-Id. If you specified the value directly, it can be immediately cross-referenced with the client records.

Language and region

Machine-translated languages are translated by clevi/cip-5.5-im and marked as such. This applies to languages with a published site bundle.

137 languages

Recommended

1

East Asia

7

Southeast Asia

11

South Asia

18

Central Asia

5

Middle East and the Caucasus

10

Western and Southern Europe

17

Britain and Ireland

4

Northern Europe and the Baltics

10

Central Europe and the Balkans

14

Eastern Europe

5

East Africa and the Horn

8

West and Central Africa

9

Southern Africa

8

The Americas

5

The Pacific

5