api.klinch.cloud

API documentation

KLINCH speaks both the Anthropic and the OpenAI API. Change the base URL and the key, and your code, SDKs and tools stay as they are.

Contents15

Base URL and formats

Every request goes to https://api.klinch.cloud. One key works with every model and both API formats:

FormatEndpointUsed by
Anthropic Messageshttps://api.klinch.cloud/v1/messagesAnthropic SDK, Claude Code
OpenAI Chat Completionshttps://api.klinch.cloud/v1/chat/completionsOpenAI SDK, Cursor, bots
OpenAI Responseshttps://api.klinch.cloud/v1/responsesCodex CLI, newer OpenAI SDKs

Any model answers in either format: call gpt-6.1-sol with the Anthropic SDK or claude-sonnet-5-5 with the OpenAI SDK. The Anthropic SDK takes the base URL without /v1, the OpenAI SDK with it.

Keys and authentication

A key looks like kl_live_… and arrives in the FunPay chat right after you buy a token pack. Add it to the klinch.app cabinet to see the balance, spend and request history.

Send the key in either header; both work on every endpoint:

  • Authorization: Bearer kl_live_… (what the OpenAI SDK sends)
  • x-api-key: kl_live_… (what the Anthropic SDK sends)

Never put the key in public code or browser apps: it spends your balance. For separate projects, create extra keys with a daily cap in the cabinet.

First request

Terminal
curl https://api.klinch.cloud/v1/messages \
  -H "x-api-key: kl_live_…" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

The reply, in the Anthropic format:

JSON
{
  "id": "msg_01…",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5-5",
  "content": [{"type": "text", "text": "Hello! How can I help?"}],
  "stop_reason": "end_turn",
  "usage": {"input_tokens": 9, "output_tokens": 12}
}

usage holds the real tokens of the request. The balance is charged that number times the model’s rate (see models and pricing).

Anthropic Messages API

The Anthropic API fields work: system, messages, max_tokens, temperature, tools, tool_choice, thinking, stream, images and documents in content, and caching with cache_control.

Streaming in Python:

Python
import anthropic

client = anthropic.Anthropic(base_url="https://api.klinch.cloud", api_key="kl_live_…")
with client.messages.stream(
    model="claude-sonnet-5-5", max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

KLINCH adds prompt caching by itself when it pays off (a long system prompt, tools, a conversation history). Cache reads cost a tenth of regular input. To opt out, send "cache_control": null in the body.

OpenAI Chat Completions

For the OpenAI SDK, LangChain, LlamaIndex, Cursor and any client with a custom base_url. messages, stream, tools, response_format (JSON), temperature and max_tokens are supported.

Python
from openai import OpenAI

client = OpenAI(base_url="https://api.klinch.cloud/v1", api_key="kl_live_…")
r = client.chat.completions.create(
    model="gpt-6.1-sol",
    messages=[{"role": "user", "content": "Hello"}],
)
print(r.choices[0].message.content)

Streaming in Node.js:

Python
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.klinch.cloud/v1", apiKey: "kl_live_…" });
const stream = await client.chat.completions.create({
  model: "deepseek-v4-pro",
  messages: [{ role: "user", content: "Explain recursion" }],
  stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content || "");

OpenAI Responses API

The format Codex CLI and newer OpenAI SDKs use. input is a string or a list of messages; stream and tools are supported.

Terminal
curl https://api.klinch.cloud/v1/responses \
  -H "Authorization: Bearer kl_live_…" \
  -H "content-type: application/json" \
  -d '{"model": "gpt-6.1-sol", "input": "Hello"}'

Tools (function calling)

Tools work in both formats and with every model. The model returns a call, you run the function and send the result in the next message, just like the official APIs.

Code
r = client.chat.completions.create(
    model="claude-sonnet-5-5",
    messages=[{"role": "user", "content": "Weather in Almaty?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
        },
    }],
)
print(r.choices[0].message.tool_calls)

List models

The models your key can use right now, with their balance rates:

Terminal
curl https://api.klinch.cloud/v1/models -H "Authorization: Bearer kl_live_…"
JSON
{
  "object": "list",
  "data": [
    {
      "id": "claude-sonnet-5-5",
      "object": "model",
      "display_name": "Claude Sonnet 5.5",
      "owned_by": "anthropic",
      "multipliers": {"input": 1, "output": 5, "cache_read": 0.1, "cache_write": 1.25}
    }
  ],
  "has_more": false
}

Descriptions and prices of every model are on Models and pricing.

Count tokens

How many input tokens a request will take, before you send it. Free.

Terminal
curl https://api.klinch.cloud/v1/messages/count_tokens \
  -H "x-api-key: kl_live_…" \
  -H "content-type: application/json" \
  -d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "Hello"}]}'

Embeddings

POST /v1/embeddings in the OpenAI format. The default model is bge-m3 (multilingual, 1024 dimensions). OpenAI’s model names (text-embedding-3-small and the rest) are accepted too. Model list: GET /v1/embeddings/models.

Code
r = client.embeddings.create(model="bge-m3", input=["first text", "second text"])
print(len(r.data[0].embedding))  # 1024

Text to speech

POST /v1/audio/speech in the OpenAI format. With the model tts-1 KLINCH picks a voice engine for the language of the text. Formats: mp3, opus, aac, flac, wav, pcm. Up to 4096 characters per request. Models and voices: GET /v1/audio/models.

Code
r = client.audio.speech.create(model="tts-1", voice="alloy", input="Привет! Это KLINCH.")
r.write_to_file("hello.mp3")

Balance and usage

The balance is counted in tokens. 1 balance token equals one Claude Sonnet 5.5 input token; other models charge more or less by their rate.

Terminal
curl https://api.klinch.cloud/v1/balance -H "Authorization: Bearer kl_live_…"
JSON
{
  "id": 123,
  "balance": 1250000,
  "unit": "tokens",
  "key_prefix": "kl_live_ab12"
}
  • GET /v1/usage?days=30: requests, tokens and spend by day and model.
  • GET /v1/history: recent requests with tokens and charges.
  • GET /v1/limits: the key’s usage limits and when they reset.

Errors

Errors come with an HTTP status and a JSON body. On the OpenAI endpoints the body follows OpenAI’s error shape.

StatusErrorWhat to do
400model_not_allowedUnknown model. The reply lists allowed models.
401invalid_tokenCheck the key and the header.
402insufficient_balanceNot enough tokens for the request. Top up.
429rate_limit_errorToo many requests from one address. Wait a minute.
5xxupstream_errorA temporary model failure. Retry or pick another model.
JSON
{"error": "insufficient_balance", "required": 5200, "balance": 310, "unit": "tokens"}

Limits

Up to 600 requests a minute per IP address, plenty for Claude Code, agents and bots. When a reply would cost more than the balance, KLINCH does not fail the request: it lowers max_tokens so the balance never goes negative.

The status page shows how the models work in real time.

Claude Code, Cursor and other tools

Claude Code needs two environment variables:

Terminal
export ANTHROPIC_BASE_URL="https://api.klinch.cloud"
export ANTHROPIC_AUTH_TOKEN="kl_live_…"
claude

Step-by-step guides for other tools, Windows and macOS are in the cabinet under Connect, and on the Claude Code and Cursor pages.

One key, one balance, every top model

Claude, GPT, Gemini, DeepSeek and Grok at a tenth of the official price. No subscription, pay as you go.