Skip to main content

Quick Start API Guide

Get started in minutes with our OpenAI-compatible API.

Get API Key

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

  1. Sign up and create an API key in the dashboard.
  2. Set the base_url in your OpenAI client to https://api.cheaptokenrouter.com/v1.
  3. 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.

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)

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.

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)

Still need help?

Reach out to support or check out our GitHub repository.

Contact Support