Chapter 15 of 211 min

15. SDK and Client Integration#

Because the API is fully OpenAI-compatible, nearly every tool that supports a custom baseURL can connect.

Python (official OpenAI SDK)#

Python
from openai import OpenAI

client = OpenAI(
    base_url="http://183.240.79.21:52099/v1",
    api_key="sk-你的YiTuoToken-Key",
)

resp = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)

Node.js (openai npm package)#

JavaScript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "http://183.240.79.21:52099/v1",
  apiKey: "sk-你的YiTuoToken-Key",
});

const resp = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "你好" }],
});
console.log(resp.choices[0].message.content);

LangChain (Python)#

Python
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="gpt-4o",
    base_url="http://183.240.79.21:52099/v1",
    api_key="sk-你的YiTuoToken-Key",
)
print(llm.invoke("你好").content)

Go#

Go
config := openai.DefaultConfig("sk-你的YiTuoToken-Key")
config.BaseURL = "http://183.240.79.21:52099/v1"
client := openai.NewClientWithConfig(config)

Anthropic SDK (via /v1/messages)#

When using the official Anthropic SDK, configure it to carry the key in an Authorization: Bearer header (the auth_token parameter) rather than the default x-api-key:

Python
from anthropic import Anthropic

client = Anthropic(
    base_url="http://183.240.79.21:52099",   # The SDK appends /v1/messages automatically
    auth_token="sk-你的YiTuoToken-Key",   # Sent as an Authorization: Bearer header
)

msg = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=256,
    messages=[{"role": "user", "content": "你好"}],
)

Desktop / Web clients#

All of the clients below support a custom OpenAI-compatible endpoint — just enter the API URL and key in their settings:

ClientAPI URLKey
Cherry Studiohttp://183.240.79.21:52099/v1your sk-...
LobeChathttp://183.240.79.21:52099/v1your sk-...
NextChathttp://183.240.79.21:52099your sk-...
Cursorhttp://183.240.79.21:52099/v1your sk-...
Difyhttp://183.240.79.21:52099/v1your sk-...

Some clients expect the root address without /v1 and append /v1 automatically; if calls return 404, try adding or removing the trailing /v1.