Skip to content

SDK Integration

Applies to: Developers Updated: 2026-07-02

CloudRouter is compatible with the official OpenAI and Anthropic SDKs. No need to change your SDK — just change two lines of config (Base URL + API Key) to switch existing code over to CloudRouter.

The API address is https://api.cloudrouter.online, with route prefix /v1, and authentication via Authorization: Bearer sk-xxx.


1. OpenAI Python SDK

The most common integration method. If you already have OpenAI code, change two lines:

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",                          # ← change to your CloudRouter Key
    base_url="https://api.cloudrouter.online/v1"     # ← add this line
)

resp = client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Hello"}]
)
print(resp.choices[0].message.content)

Install: pip install openai


2. OpenAI Node.js SDK

javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "https://api.cloudrouter.online/v1",
});

const resp = await client.chat.completions.create({
  model: "claude-sonnet-4-6",
  messages: [{ role: "user", content: "Hello" }],
});

console.log(resp.choices[0].message.content);

Install: npm install openai


3. Anthropic SDK

If you use Claude's native SDK, change base_url to point at CloudRouter:

python
from anthropic import Anthropic

client = Anthropic(
    api_key="YOUR_API_KEY",
    base_url="https://api.cloudrouter.online"
)

resp = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}]
)
print(resp.content[0].text)

Install: pip install anthropic

The Anthropic SDK uses the /v1/messages endpoint, where max_tokens is a required parameter.


4. Other languages / general pattern

CloudRouter is a standard HTTP API; any language that can make HTTP requests can integrate.

Go

go
// Use the OpenAI-compatible endpoint, set a custom BaseURL
config := openai.DefaultConfig("YOUR_API_KEY")
config.BaseURL = "https://api.cloudrouter.online/v1"
client := openai.NewClientWithConfig(config)

Generic curl (any environment)

bash
curl https://api.cloudrouter.online/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-sonnet-4-6","messages":[{"role":"user","content":"Hello"}]}'

5. Integration checklist

When migrating to CloudRouter, confirm each item:

  • [ ] base_url / baseURL points at CloudRouter
  • [ ] api_key has been changed to your CloudRouter Key (starts with sk-)
  • [ ] The model field contains a call name copied from the console's "Call Guide" (bare name or with fingerprint, either works)
  • [ ] The target group / model is within your account's available range
  • [ ] The rest of your business code requires no changes

For the difference between the bare-name and with-fingerprint forms of the model field, see Call Guide & Dual Routing.


Next steps


Contact us