Skip to main content

First API Call

CleverThis exposes an OpenAI-compatible inference API, which means any tool or SDK built for OpenAI works without modification — just point it at the CleverThis base URL and supply a ct_live_ API key.

This page walks you through generating an API key and sending your first chat completion request.

1. Generate an API key

  1. Open the Dashboard and click your workspace name in the top-left.
  2. Navigate to Settings → API Keys.
  3. Click New Key, give it a name (e.g. dev-test), and confirm.
  4. Copy the key immediately — it is shown only once. Inference keys have the prefix ct_live_.

2. Send a chat completion

Replace <YOUR_KEY> with your key and <MODEL_ID> with any model ID visible in the Library (e.g. openai/gpt-4o):

curl https://api.cleverthis.com/v1/chat/completions \
-H "Authorization: Bearer <YOUR_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "<MODEL_ID>",
"messages": [
{"role": "user", "content": "Hello, CleverThis!"}
]
}'

A successful response looks like:

{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"model": "openai/gpt-4o",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Hello! How can I help you today?"},
"finish_reason": "stop"
}
],
"usage": {"prompt_tokens": 10, "completion_tokens": 9, "total_tokens": 19}
}

3. Use with the OpenAI Python SDK

from openai import OpenAI

client = OpenAI(
api_key="ct_live_YOUR_KEY",
base_url="https://api.cleverthis.com/v1",
)

response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Hello, CleverThis!"}],
)
print(response.choices[0].message.content)
Coming soon

Full error reference and troubleshooting for common first-call failures (401, 402, 429) is being added to the Errors page.