// Quick Start

Documentation

Configure your API endpoint and key via environment variables — no code changes needed to integrate PioModel.

01API Endpoints

Anthropic SDK (Claude Code etc.)
https://api.piomodel.com
OpenAI SDK / HTTP
https://api.piomodel.com/v1
KEY
Create a key in the console under "API Key Management". It looks like sk-your-api-key. Pass it in requests as Authorization: Bearer sk-...

02Environment Variables

Windows Setup

Valid for the current terminal session only. Closes when the window closes. Good for quick testing.

# PowerShell (valid for current session only)
$env:ANTHROPIC_BASE_URL = "https://api.piomodel.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-your-api-key"

macOS / Linux Setup

Valid for the current terminal session only. Closes when the window closes. Good for quick testing.

# bash / zsh (valid for current session only)
export ANTHROPIC_BASE_URL="https://api.piomodel.com"
export ANTHROPIC_AUTH_TOKEN="sk-your-api-key"

03Tool Integration

Mainstream AI coding tools can connect directly to PioModel — just set the environment variables or configuration below.

Claude Code CLI

Anthropic's official CLI — connect to PioModel via environment variables, no code changes needed.

Go to API Key Management to download a one-click setup script →
# bash / zsh (valid for current session only)
export ANTHROPIC_BASE_URL="https://api.piomodel.com"
export ANTHROPIC_AUTH_TOKEN="sk-your-api-key"

Then launch with:

claude

Codex CLI

OpenAI's official Codex CLI — uses the /v1/responses endpoint. Note: base_url must include /v1.

Edit ~/.codex/config.toml:

model_provider = "piomodel"
model = "gpt-5.3-codex"
model_reasoning_effort = "high"
disable_response_storage = true
preferred_auth_method = "apikey"

[model_providers.piomodel]
name = "piomodel"
base_url = "https://api.piomodel.com/v1"
wire_api = "responses"
env_key = "PIOMODEL_API_KEY"

Then set the API key as an environment variable:

# bash / zsh
export PIOMODEL_API_KEY="sk-your-api-key"

Then launch with:

codex

Cursor / Windsurf

Override the OpenAI endpoint and API key in the settings.

{
  "openai.baseUrl": "https://api.piomodel.com/v1",
  "openai.apiKey": "sk-your-api-key"
}

Cline (VS Code)

Select the OpenAI Compatible provider in Cline and enter the endpoint, key, and model name.

Provider   : OpenAI Compatible
Base URL   : https://api.piomodel.com/v1
API Key    : sk-your-api-key
Model      : claude-sonnet-4-5-20250929

04Code Examples

from anthropic import Anthropic

# Automatically reads ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN from env
client = Anthropic()

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

Install: pip install anthropic / openai · npm install openai

05Streaming

Add stream: true to your request body to enable SSE streaming — ideal for real-time chat UIs.

from anthropic import Anthropic

client = Anthropic()

with client.messages.stream(
    model="claude-sonnet-4-5-20250929",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku about Go."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

06Automatic Format Conversion

PioModel performs transparent two-way conversion between Anthropic Messages and OpenAI Chat at the gateway level. This means you can call the same model in either Anthropic style or OpenAI style — one codebase, any model.

Key field mappings between the two styles:

Anthropic StyleOpenAI StyleDescription
systemmessages[role=system]System prompt is positioned differently; the gateway handles it automatically
max_tokens(必填)max_tokens(可选)When omitted, the gateway applies the model's default limit
content 分块数组content 字符串Text/image blocks convert to and from strings
stop_reasonfinish_reasonFinish reason field name mapping
TIP
Already have OpenAI code and want to call Claude? Just change base_url and model — no need to touch the message structure.

07Multimodal

Image generation uses the same gateway and API key, billed by usage.

img = client.images.generate(
    model="gpt-image-2",
    prompt="夜幕下的城市天际线,电影感",
    size="1024x1024",
)
print(img.data[0].url)

08Function Calling

Define callable functions using OpenAI-style tools. The model returns tool_calls when needed, and your code executes them and returns the results.

tools = [{
  "type": "function",
  "function": {
    "name": "get_weather",
    "description": "查询某城市天气",
    "parameters": {
      "type": "object",
      "properties": {"city": {"type": "string"}},
      "required": ["city"],
    },
  },
}]

resp = client.chat.completions.create(
    model="claude-sonnet-4-5-20250929",
    messages=[{"role": "user", "content": "上海今天天气怎么样?"}],
    tools=tools,
)
print(resp.choices[0].message.tool_calls)

09Error Handling

/v1/* endpoints follow OpenAI's error format — responses contain type / code / message.

{
  "error": {
    "type": "invalid_request_error",
    "code": "insufficient_quota",
    "message": "余额不足"
  }
}

Common error codes

HTTPDescription
401API key is invalid or missing
402Insufficient balance — please top up
429Rate limited or daily quota exhausted
503All upstream channels unavailable (circuit broken)
See all models and pricing →