Language Models
User manual for language models (LLMs).
Text generation is supported through OpenAI-compatible, Anthropic-compatible, and Gemini AI Studio native protocols.
OpenAI-Compatible Interface (Recommended)
For features not covered here, refer to the OpenAI API Reference.
Message Roles
| Role | Purpose | Example |
|---|---|---|
system | Sets the model's behavior and persona | "You are a pediatrician with 10 years of experience." |
user | The end user's input, passed to the model | "How should I handle a toddler's persistent low-grade fever?" |
assistant | Prior model responses, providing examples of how the model should respond | "Take the temperature first..." |
Use message roles to steer the model with layered instructions and improve output quality. Roles are not always deterministic, so try several approaches, compare the results, and pick what works best for you.
Basic Conversation
from openai import OpenAI
client = OpenAI(
base_url="https://api.calgine.com.cn/v1",
api_key="API_KEY", # Replace with your API key from the console
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.calgine.com.cn/v1",
apiKey: "API_KEY", // Replace with your API key from the console
});
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);Streaming
from openai import OpenAI
client = OpenAI(
base_url="https://api.calgine.com.cn/v1",
api_key="API_KEY",
)
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Write a short poem about spring."}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.calgine.com.cn/v1",
apiKey: "API_KEY",
});
const stream = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Write a short poem about spring." }],
stream: true,
});
for await (const chunk of stream) {
if (chunk.choices[0]?.delta?.content) {
process.stdout.write(chunk.choices[0].delta.content);
}
}Tool Calling (Function Calling)
For more details, see the OpenAI tool use guide.
from openai import OpenAI
client = OpenAI(
base_url="https://api.calgine.com.cn/v1",
api_key="API_KEY",
)
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
},
"required": ["city"],
},
},
}
]
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What's the weather in London?"}],
tools=tools,
)
print(response.choices[0].message)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.calgine.com.cn/v1",
apiKey: "API_KEY",
});
const tools = [
{
type: "function",
function: {
name: "get_weather",
description: "Get the current weather for a city",
parameters: {
type: "object",
properties: {
city: { type: "string", description: "City name" },
},
required: ["city"],
},
},
},
];
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "What's the weather in London?" }],
tools: tools,
});
console.log(response.choices[0].message);Response API
- This interface currently only supports OpenAI models
- For usage details, refer to the OpenAI documentation
Notes
- Set
OPENAI_BASE_URLtohttps://api.calgine.com.cn/v1 - Set
OPENAI_API_KEYto your API key - Some models do not support parameters such as
presence_penalty,frequency_penalty, orlogit_bias; they are ignored when passed - The legacy
function_callparameter is deprecated — usetoolsinstead
Anthropic-Compatible Interface
For features not covered here, refer to the Anthropic API Reference.
Basic Conversation
import anthropic
client = anthropic.Anthropic(
base_url="https://api.calgine.com.cn/anthropic",
api_key="API_KEY", # Replace with your API key from the console
)
message = client.messages.create(
model="claude-opus-4-5-20251101",
max_tokens=1024,
messages=[{"role": "user", "content": "Explain machine learning in simple terms."}],
)
print(message.content[0].text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.calgine.com.cn/anthropic",
apiKey: "API_KEY", // Replace with your API key from the console
});
const message = await client.messages.create({
model: "claude-opus-4-5-20251101",
maxTokens: 1024,
messages: [{ role: "user", content: "Explain machine learning in simple terms." }],
});
console.log(message.content[0].text);Streaming
import anthropic
client = anthropic.Anthropic(
base_url="https://api.calgine.com.cn/anthropic",
api_key="API_KEY",
)
with client.messages.stream(
model="claude-opus-4-5-20251101",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a short poem about spring."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.calgine.com.cn/anthropic",
apiKey: "API_KEY",
});
const stream = await client.messages.stream({
model: "claude-opus-4-5-20251101",
maxTokens: 1024,
messages: [{ role: "user", content: "Write a short poem about spring." }],
});
for await (const chunk of stream) {
if (chunk.type === "content_block_delta" && chunk.delta.type === "text_delta") {
process.stdout.write(chunk.delta.text);
}
}Tool Calling
For more details, see the Anthropic tool use guide.
import anthropic
client = anthropic.Anthropic(
base_url="https://api.calgine.com.cn/anthropic",
api_key="API_KEY",
)
tools = [
{
"name": "get_weather",
"description": "Get the current weather for a city",
"input_schema": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
},
"required": ["city"],
},
}
]
message = client.messages.create(
model="claude-opus-4-5-20251101",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "What's the weather in London?"}],
)
print(message.content)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.calgine.com.cn/anthropic",
apiKey: "API_KEY",
});
const tools = [
{
name: "get_weather",
description: "Get the current weather for a city",
input_schema: {
type: "object",
properties: {
city: { type: "string", description: "City name" },
},
required: ["city"],
},
},
];
const message = await client.messages.create({
model: "claude-opus-4-5-20251101",
maxTokens: 1024,
tools: tools,
messages: [{ role: "user", content: "What's the weather in London?" }],
});
console.log(message.content);- Set
ANTHROPIC_BASE_URLtohttps://api.calgine.com.cn/anthropic - Set
ANTHROPIC_API_KEYto your API key
Gemini AI Studio Compatible Interface
Gemini models can be called directly in the official Google AI Studio API format — no conversion to OpenAI format required. Ideal for projects already using the Google genai SDK. For features not covered here, refer to the Google AI Studio documentation.
Basic Conversation
from google import genai
from google.genai import types
client = genai.Client(
api_key="API_KEY", # Replace with your API key from the console
http_options=types.HttpOptions(
api_version="v1beta",
base_url="https://api.calgine.com.cn",
),
)
response = client.models.generate_content(
model="gemini-2.5-pro",
contents="Hello, please introduce yourself.",
)
print(response.text)import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({
apiKey: "API_KEY", // Replace with your API key from the console
httpOptions: {
apiVersion: "v1beta",
baseUrl: "https://api.calgine.com.cn",
},
});
const response = await ai.models.generateContent({
model: "gemini-2.5-pro",
contents: "Hello, please introduce yourself.",
});
console.log(response.text);Streaming
from google import genai
from google.genai import types
client = genai.Client(
api_key="API_KEY",
http_options=types.HttpOptions(
api_version="v1beta",
base_url="https://api.calgine.com.cn",
),
)
for chunk in client.models.generate_content_stream(
model="gemini-2.5-pro",
contents="Write a short poem about spring.",
):
print(chunk.text, end="", flush=True)import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({
apiKey: "API_KEY",
httpOptions: {
apiVersion: "v1beta",
baseUrl: "https://api.calgine.com.cn",
},
});
const response = await ai.models.generateContentStream({
model: "gemini-2.5-pro",
contents: "Write a short poem about spring.",
});
for await (const chunk of response) {
process.stdout.write(chunk.text());
}Tool Calling (Function Calling)
For more details, see the Google AI Studio function calling guide.
from google import genai
from google.genai import types
client = genai.Client(
api_key="API_KEY",
http_options=types.HttpOptions(
api_version="v1beta",
base_url="https://api.calgine.com.cn",
),
)
get_weather = types.FunctionDeclaration(
name="get_weather",
description="Get the current weather for a city",
parameters=types.Schema(
type="OBJECT",
properties={"city": types.Schema(type="STRING", description="City name")},
required=["city"],
),
)
response = client.models.generate_content(
model="gemini-2.5-pro",
contents="What's the weather in London?",
config=types.GenerateContentConfig(
tools=[types.Tool(function_declarations=[get_weather])]
),
)
print(response.candidates[0].content.parts)import { GoogleGenAI, Type } from "@google/genai";
const ai = new GoogleGenAI({
apiKey: "API_KEY",
httpOptions: {
apiVersion: "v1beta",
baseUrl: "https://api.calgine.com.cn",
},
});
const response = await ai.models.generateContent({
model: "gemini-2.5-pro",
contents: "What's the weather in London?",
config: {
tools: [
{
functionDeclarations: [
{
name: "get_weather",
description: "Get the current weather for a city",
parameters: {
type: Type.OBJECT,
properties: { city: { type: Type.STRING, description: "City name" } },
required: ["city"],
},
},
],
},
],
},
});
console.log(response.candidates[0].content.parts);- Set
base_url/baseUrltohttps://api.calgine.com.cn(without the/v1betasuffix — the SDK appends it automatically) - Set
api_version/apiVersiontov1beta - Set
api_key/apiKeyto your API key - Install dependencies:
pip install google-genaifor Python,npm install @google/genaifor Node.js