api.klinch.cloud

Code examples

Copy an example, put your key into KLINCH_API_KEY and run it. Any model id from the model list works in any example.

Contents7

Before you run

Every example reads the key from an environment variable, so it never lands in your code or in git:

Terminal
export KLINCH_API_KEY="kl_live_your_key"
PowerShell
$env:KLINCH_API_KEY="kl_live_your_key"

OpenAI-format SDKs and tools take the address with /v1; the Anthropic SDK, Claude Code, Cline and Aider take it without.

curl

curl/chat-completions.sh. OpenAI Chat Completions format. open the file

Terminal
#!/usr/bin/env sh
# OpenAI Chat Completions format. Any model from https://klinch.app/models/ works here.
curl https://api.klinch.cloud/v1/chat/completions \
  -H "Authorization: Bearer $KLINCH_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

curl/messages.sh. Anthropic Messages format, the same key. open the file

Terminal
#!/usr/bin/env sh
# Anthropic Messages format. The same key works for both formats.
curl https://api.klinch.cloud/v1/messages \
  -H "x-api-key: $KLINCH_API_KEY" \
  -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"}]
  }'

curl/models-and-balance.sh. The model list and the balance left on the key. open the file

Terminal
#!/usr/bin/env sh
# Every model your key can call, then the balance left on the key.
curl https://api.klinch.cloud/v1/models -H "Authorization: Bearer $KLINCH_API_KEY"
curl https://api.klinch.cloud/v1/balance -H "Authorization: Bearer $KLINCH_API_KEY"

Python

python/openai_chat.py. OpenAI SDK, a plain request. open the file

Python
# pip install openai
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.klinch.cloud/v1", api_key=os.environ["KLINCH_API_KEY"])

r = client.chat.completions.create(
    model="claude-sonnet-5-5",
    messages=[{"role": "user", "content": "Explain recursion in two sentences"}],
)
print(r.choices[0].message.content)

python/openai_stream.py. OpenAI SDK with streaming. open the file

Python
# pip install openai
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.klinch.cloud/v1", api_key=os.environ["KLINCH_API_KEY"])

stream = client.chat.completions.create(
    model="gpt-6.2-sol",
    messages=[{"role": "user", "content": "Write a short poem about the sea"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()

python/anthropic_stream.py. Anthropic SDK with streaming. The address goes without /v1. open the file

Python
# pip install anthropic
import os

import anthropic

# The Anthropic SDK takes the address WITHOUT /v1.
client = anthropic.Anthropic(base_url="https://api.klinch.cloud", api_key=os.environ["KLINCH_API_KEY"])

with client.messages.stream(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku about code"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
print()

python/tools.py. Function calling, from the request to the final answer. open the file

Python
# pip install openai
# Function calling: the model asks to call get_weather, you run it and send the result back.
import json
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.klinch.cloud/v1", api_key=os.environ["KLINCH_API_KEY"])
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Current weather in a city",
        "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
    },
}]
messages = [{"role": "user", "content": "What is the weather in Almaty?"}]

r = client.chat.completions.create(model="claude-sonnet-5-5", messages=messages, tools=tools)
call = r.choices[0].message.tool_calls[0]
messages.append(r.choices[0].message)
messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps({"city": json.loads(call.function.arguments)["city"], "temp_c": 4})})

r = client.chat.completions.create(model="claude-sonnet-5-5", messages=messages, tools=tools)
print(r.choices[0].message.content)

python/embeddings.py. Embeddings for search and RAG. open the file

Python
# pip install openai
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.klinch.cloud/v1", api_key=os.environ["KLINCH_API_KEY"])

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

python/langchain_chat.py. LangChain with ChatOpenAI. open the file

Python
# pip install langchain-openai
import os

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://api.klinch.cloud/v1",
    api_key=os.environ["KLINCH_API_KEY"],
    model="claude-sonnet-5-5",
)
print(llm.invoke("Give three names for a coffee shop").content)

python/llamaindex_chat.py. LlamaIndex with OpenAILike. open the file

Python
# pip install llama-index-llms-openai-like
import os

from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    api_base="https://api.klinch.cloud/v1",
    api_key=os.environ["KLINCH_API_KEY"],
    model="deepseek-v4-pro",
    is_chat_model=True,
    is_function_calling_model=True,
    context_window=128000,
)
print(llm.complete("What is a vector database?"))

python/litellm_chat.py. LiteLLM: the openai/ prefix and your api_base. open the file

Python
# pip install litellm
import os

import litellm

r = litellm.completion(
    model="openai/claude-sonnet-5-5",  # "openai/" = an OpenAI-compatible endpoint
    api_base="https://api.klinch.cloud/v1",
    api_key=os.environ["KLINCH_API_KEY"],
    messages=[{"role": "user", "content": "Hello"}],
)
print(r.choices[0].message.content)

Node.js and TypeScript

node/openai_stream.mjs. OpenAI SDK with streaming. open the file

JavaScript
// npm install openai
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.klinch.cloud/v1", apiKey: process.env.KLINCH_API_KEY });

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 || "");
process.stdout.write("\n");

node/anthropic.mjs. Anthropic SDK. The address goes without /v1. open the file

JavaScript
// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

// The Anthropic SDK takes the address WITHOUT /v1.
const client = new Anthropic({ baseURL: "https://api.klinch.cloud", apiKey: process.env.KLINCH_API_KEY });

const msg = await client.messages.create({
  model: "claude-sonnet-5-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello" }],
});
console.log(msg.content[0].text);

node/ai_sdk.mjs. Vercel AI SDK with @ai-sdk/openai-compatible. open the file

JavaScript
// npm install ai @ai-sdk/openai-compatible
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";

const klinch = createOpenAICompatible({
  name: "klinch",
  baseURL: "https://api.klinch.cloud/v1",
  apiKey: process.env.KLINCH_API_KEY,
});

const result = streamText({ model: klinch("claude-sonnet-5-5"), prompt: "Write a tagline for a bakery" });
for await (const part of result.textStream) process.stdout.write(part);
process.stdout.write("\n");

Go and PHP

go/main.go. Plain HTTP, no libraries. open the file

Go
// go run main.go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

func main() {
	body, _ := json.Marshal(map[string]any{
		"model":    "deepseek-v4-pro",
		"messages": []map[string]string{{"role": "user", "content": "Hello"}},
	})
	req, _ := http.NewRequest("POST", "https://api.klinch.cloud/v1/chat/completions", bytes.NewReader(body))
	req.Header.Set("Authorization", "Bearer "+os.Getenv("KLINCH_API_KEY"))
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	var out struct {
		Choices []struct {
			Message struct{ Content string } `json:"message"`
		} `json:"choices"`
	}
	json.NewDecoder(resp.Body).Decode(&out)
	if len(out.Choices) == 0 {
		fmt.Println("no answer, HTTP", resp.Status)
		return
	}
	fmt.Println(out.Choices[0].Message.Content)
}

php/chat.php. cURL, no libraries. open the file

PHP
<?php
// php chat.php
$ch = curl_init('https://api.klinch.cloud/v1/chat/completions');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('KLINCH_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'model' => 'claude-sonnet-5-5',
        'messages' => [['role' => 'user', 'content' => 'Hello']],
    ]),
]);
$r = json_decode(curl_exec($ch), true);
echo $r['choices'][0]['message']['content'] ?? json_encode($r), PHP_EOL;

IDE and agent templates

ide/claude-code/settings.json. Claude Code: ~/.claude/settings.json, works in any terminal. open the file

JSON
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.klinch.cloud",
    "ANTHROPIC_AUTH_TOKEN": "kl_live_your_key",
    "ANTHROPIC_MODEL": "claude-sonnet-5-5"
  }
}

ide/codex/config.toml. Codex CLI, the Codex app and the VS Code extension: ~/.codex/config.toml. open the file

TOML
# ~/.codex/config.toml (Windows: C:\Users\<name>\.codex\config.toml)
# Then set the key: export KLINCH_API_KEY="kl_live_your_key" and run codex.
model = "gpt-6.2-sol"
model_provider = "klinch"

[model_providers.klinch]
name = "Klinch"
base_url = "https://api.klinch.cloud/v1"
env_key = "KLINCH_API_KEY"
wire_api = "responses"

ide/opencode/opencode.json. OpenCode: opencode.json in the project folder, the key from KLINCH_API_KEY. open the file

JSON
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "klinch": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Klinch",
      "options": { "baseURL": "https://api.klinch.cloud/v1", "apiKey": "{env:KLINCH_API_KEY}" },
      "models": {
        "claude-sonnet-5-5": { "name": "Claude Sonnet 5.5", "tool_call": true, "limit": { "context": 200000, "output": 16384 } },
        "gpt-6.2-sol": { "name": "GPT 6.2 Sol", "tool_call": true, "limit": { "context": 128000, "output": 16384 } },
        "deepseek-v4-pro": { "name": "DeepSeek V4 Pro", "tool_call": true, "limit": { "context": 128000, "output": 16384 } }
      }
    }
  },
  "model": "klinch/claude-sonnet-5-5"
}

ide/continue/config.yaml. Continue for VS Code and JetBrains: ~/.continue/config.yaml. open the file

YAML
# ~/.continue/config.yaml
name: Klinch
version: 1.0.0
schema: v1
models:
  - name: Klinch Claude Sonnet 5.5
    provider: openai
    model: claude-sonnet-5-5
    apiBase: https://api.klinch.cloud/v1
    apiKey: kl_live_your_key
    roles: [chat, edit, apply]
  - name: Klinch DeepSeek V4 Pro
    provider: openai
    model: deepseek-v4-pro
    apiBase: https://api.klinch.cloud/v1
    apiKey: kl_live_your_key
    roles: [chat, edit, apply, autocomplete]

ide/zed/settings.json. Zed: the language_models block of settings.json. open the file

JSON
// Zed → Settings → Open Settings. Then Agent panel → Settings → Klinch: paste the key.
{
  "language_models": {
    "openai_compatible": {
      "Klinch": {
        "api_url": "https://api.klinch.cloud/v1",
        "available_models": [
          { "name": "claude-sonnet-5-5", "max_tokens": 200000 },
          { "name": "deepseek-v4-pro", "max_tokens": 128000 }
        ]
      }
    }
  }
}

ide/aider/aider.sh. Aider in the terminal. open the file

Terminal
#!/usr/bin/env sh
# pip install aider-chat. Windows PowerShell: $env:ANTHROPIC_API_BASE="https://api.klinch.cloud"
export ANTHROPIC_API_BASE="https://api.klinch.cloud"
export ANTHROPIC_API_KEY="$KLINCH_API_KEY"
aider --model anthropic/claude-sonnet-5-5

ide/cline/README.md. Cline, Roo Code and Kilo Code: the settings fields. open the file

Markdown
# Cline, Roo Code, Kilo Code

Extension settings (the gear in the panel):

| Field | Value |
|---|---|
| API Provider | Anthropic |
| Use custom base URL | `https://api.klinch.cloud` (without /v1) |
| Anthropic API Key | `kl_live_your_key` |
| Model | `claude-sonnet-5-5` |

With the «OpenAI Compatible» provider the address is `https://api.klinch.cloud/v1` (with /v1) and any model from
https://klinch.app/models/ works.

Next

One key and one balance for Claude, GPT, Gemini and more

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