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

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)

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)

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)

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

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)

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)

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)
  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

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)

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)

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)
  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