Back to blog

Getting startedGuide

Your first API request with CheapTokens

From a new account to a working request in about five minutes — balance, API key, model ID and ready-to-run curl, Python and JavaScript examples.

By CheapTokens TeamPublished 3 min read

Terminal window with a curl request to api.cheaptokens.dev/v1/chat/completions and the JSON response
On this page
  1. What you need
  2. Step 1. Create an account and top up
  3. Step 2. Copy your API key
  4. Step 3. Pick a model
  5. Step 4. Send the request
  6. curl
  7. Python
  8. JavaScript
  9. Anthropic-style clients
  10. If something goes wrong
  11. What it costs

This guide takes you from a new account to a working request. You need an email address, a small balance and a terminal. The API is OpenAI-compatible, so if you have called OpenAI before, only two things change: the base URL and the key.

What you need#

  • An account. Sign-up is by email — no password, we send you a sign-in link.
  • A balance. There is no subscription: you top up a USD balance and every request is charged per token at the model's fixed rate.
  • An API key from your dashboard.

Step 1. Create an account and top up#

Open the sign-up page, enter your email and follow the link from the letter. In the dashboard press Top up and choose how to pay:

  • Crypto — from $5; a 5% deposit fee applies.
  • Card — through a partner, who charges its own fee.

Step 2. Copy your API key#

As soon as your balance is above zero — after a top-up or a referral bonus — the dashboard creates your API key and shows it once. Copy it right away and keep it out of your code, for example in an environment variable:

bash
export CHEAPTOKENS_API_KEY="paste-your-key-here"

If the key leaks, press Rotate: you get a new key and the old one stops working.

Step 3. Pick a model#

Requests need the full model ID — with the prefix before the slash, exactly as the API lists it. The catalog at the time of writing (October 2026):

Model API model ID Context Max output
GLM-5.3-Flash zai-org/GLM-5.3-Flash 390K tokens 8,192 tokens
DeepSeek-V4-Flash deepseek-ai/DeepSeek-V4-Flash-0731 380K tokens 32,768 tokens
MiniMax-M2.7 MiniMaxAI/MiniMax-M2.7 200K tokens 8,192 tokens

The catalog can change, so the source of truth is the API itself. This request needs no key:

bash
curl https://api.cheaptokens.dev/v1/models

Step 4. Send the request#

curl#

bash
curl https://api.cheaptokens.dev/v1/chat/completions \
  -H "Authorization: Bearer $CHEAPTOKENS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-ai/DeepSeek-V4-Flash-0731",
    "messages": [{"role": "user", "content": "Say hello in three languages"}]
  }'

A successful answer comes back in the standard Chat Completions format. A shortened example — your text, IDs and numbers will differ, and the response may carry extra service fields:

json
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "deepseek-ai/DeepSeek-V4-Flash-0731",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "Hello! Hola! Bonjour!" },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 14, "completion_tokens": 9, "total_tokens": 23 }
}
  • The text is in choices[0].message.content.
  • Token usage is in usage: prompt_tokens — input, completion_tokens — output. These two numbers are what the request is charged for.

Python#

Install the official SDK with pip install openai and point it at our base URL:

python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.cheaptokens.dev/v1",
    api_key=os.environ["CHEAPTOKENS_API_KEY"],
)
resp = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Flash-0731",
    messages=[{"role": "user", "content": "Say hello in three languages"}],
)
print(resp.choices[0].message.content)
print("tokens in/out:", resp.usage.prompt_tokens, resp.usage.completion_tokens)

JavaScript#

Install the SDK with npm install openai:

javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.cheaptokens.dev/v1",
  apiKey: process.env.CHEAPTOKENS_API_KEY,
});
const resp = await client.chat.completions.create({
  model: "deepseek-ai/DeepSeek-V4-Flash-0731",
  messages: [{ role: "user", content: "Say hello in three languages" }],
});
console.log(resp.choices[0].message.content);

Anthropic-style clients#

Clients built for the Anthropic Messages API use the root address without /v1 — https://api.cheaptokens.dev — and send the key in the x-api-key header. The Anthropic SDKs add the path and the header themselves; you only set the base URL and the key.

If something goes wrong#

  • 401 Invalid API key — the key is mistyped or was rotated. Check that you pasted it whole; the dashboard shows a key only once, so if it is lost, press Rotate to get a new one.
  • 402 — the balance is used up, or the request went out without the Authorization header.
  • 400 Model "…" not found — use the full model ID from /v1/models, including the prefix before the slash.
  • 404 — check the address: OpenAI-style clients need /v1 at the end of the base URL.

More cases and fixes: Common connection errors and how to fix them.

What it costs#

Each request is charged for input and output tokens separately, at the model's rate per million tokens. Current prices — the same data as on the pricing page:

Model Context Input $/1M Output $/1M OpenRouter in OpenRouter out
GLM-5.3-Flash reasoning 390K $0.027 $0.08 $0.048 $0.20
DeepSeek-V4-Flash 380K $0.0221 $0.10 $0.016 $0.64
MiniMax-M2.7 200K $0.05 $0.15 $0.30 $1.20

Prices in USD per 1M tokens. OpenRouter figures shown for comparison and may change.

Next step: connect a coding agent, for example Cline, or learn to estimate what an AI agent will cost.

Recommending CheapTokens to other developers? The referral program credits you a percentage of their top-ups.