Skip to content

Language Models ​

User manual for language models (LLMs).

Text generation is supported through OpenAI-compatible, Anthropic-compatible, and Gemini AI Studio native protocols.

For features not covered here, refer to the OpenAI API Reference.

Message Roles ​

RolePurposeExample
systemSets the model's behavior and persona"You are a pediatrician with 10 years of experience."
userThe end user's input, passed to the model"How should I handle a toddler's persistent low-grade fever?"
assistantPrior 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 ​

python
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)
js
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 ​

python
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)
js
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.

python
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)
js
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 ​

  1. Set OPENAI_BASE_URL to https://api.calgine.com.cn/v1
  2. Set OPENAI_API_KEY to your API key
  3. Some models do not support parameters such as presence_penalty, frequency_penalty, or logit_bias; they are ignored when passed
  4. The legacy function_call parameter is deprecated — use tools instead

Anthropic-Compatible Interface ​

For features not covered here, refer to the Anthropic API Reference.

Basic Conversation ​

python
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)
js
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 ​

python
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)
js
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.

python
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)
js
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);
  1. Set ANTHROPIC_BASE_URL to https://api.calgine.com.cn/anthropic
  2. Set ANTHROPIC_API_KEY to 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 ​

python
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)
js
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 ​

python
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)
js
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.

python
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)
js
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);
  1. Set base_url / baseUrl to https://api.calgine.com.cn (without the /v1beta suffix — the SDK appends it automatically)
  2. Set api_version / apiVersion to v1beta
  3. Set api_key / apiKey to your API key
  4. Install dependencies: pip install google-genai for Python, npm install @google/genai for Node.js