Quick Start API Guide
Get started in minutes with our OpenAI-compatible API.
Our API is fully compatible with the OpenAI specification. This allows you to use existing tools and libraries to interact with our service with minimal changes.
Steps
- Sign up and create an API key in the dashboard.
- Set the
base_url
in your OpenAI client tohttps://api.cheaptokenrouter.com/v1
. - Use your generated API key for authentication.
Authentication
All API requests require a bearer token in the Authorization
header.
You can create and manage your API keys in the dashboard.
Header Format
Authorization: Bearer sk_your_api_key_here
Using Environment Variables
For security, we recommend storing your API key in an environment variable (e.g. CTR_API_KEY
) and loading it in your application.
Avoid committing keys to source control.
API Reference (OpenAI Compatible)
API Base URL
All API requests should be made to the following base URL:
https://api.cheaptokenrouter.com/v1
POST /chat/completions
Creates a model response for the given chat conversation.
- Request
- Response (200)
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.cheaptokenrouter.com/v1",
api_key=os.environ.get("CTR_API_KEY"),
)
chat_completion = client.chat.completions.create(
model="moonshotai/kimi-k2-cheap",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello! What is the capital of France?"}
]
)
print(chat_completion.choices[0].message.content)
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1677652288,
"model": "moonshotai/kimi-k2-cheap",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I am an AI assistant."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 9,
"total_tokens": 19
}
}
Error Responses
Errors use standard HTTP status codes and a JSON payload that is compatible with the OpenAI error format.
Code Examples
Copyable examples for popular languages. Use the copy button to paste them into your project.
- Python
- Node.js / TS
- cURL
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.cheaptokenrouter.com/v1",
api_key=os.environ.get("CTR_API_KEY"),
)
chat_completion = client.chat.completions.create(
model="moonshotai/kimi-k2-cheap",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello! What is the capital of France?"}
]
)
print(chat_completion.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.cheaptokenrouter.com/v1",
apiKey: process.env.CTR_API_KEY,
});
async function main() {
const chatCompletion = await client.chat.completions.create({
model: "moonshotai/kimi-k2-cheap",
messages: [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello! What is the capital of France?"}
],
});
console.log(chatCompletion.choices[0].message.content);
}
main();
curl https://api.cheaptokenrouter.com/v1/chat/completions \
-H "Authorization: Bearer sk_...your_key..." \
-H "Content-Type: application/json" \
-d '{
"model": "moonshotai/kimi-k2-cheap",
"messages": [
{
"role": "user",
"content": "Hello world!"
}
]
}'
Still need help?
Reach out to support or check out our GitHub repository.