Skip to content
中

Call XiuRouter with an SDK

Configure the OpenAI Python or JavaScript SDK and understand Chat Completions parameters and compatibility limits.

Updated Reviewed
View Markdown

Use XiuRouter with an OpenAI-compatible SDK by setting its Base URL to https://router-api.xiu.ai/v1, providing a dedicated XiuRouter API key, and copying an exact model ID from the current catalog.

Before you start

Keep the key out of source files, lockfiles, frontend bundles, and Git. These examples read environment variables:

export XIUROUTER_API_KEY="YOUR_XIUROUTER_API_KEY"
export XIUROUTER_MODEL="YOUR_MODEL_ID"

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["XIUROUTER_API_KEY"],
    base_url="https://router-api.xiu.ai/v1",
)

response = client.chat.completions.create(
    model=os.environ["XIUROUTER_MODEL"],
    messages=[
        {"role": "user", "content": "Reply only: Python SDK connected"}
    ],
)

print(response.choices[0].message.content)

JavaScript

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.XIUROUTER_API_KEY,
  baseURL: "https://router-api.xiu.ai/v1",
});

const response = await client.chat.completions.create({
  model: process.env.XIUROUTER_MODEL,
  messages: [
    { role: "user", content: "Reply only: JavaScript SDK connected" },
  ],
});

console.log(response.choices[0].message.content);

Common parameters

Parameter Purpose Limits
model Select the model Required; copy the exact ID from the catalog or model list
messages Supply conversation messages Used by Chat Completions; roles and multimodal content depend on the model
max_completion_tokens Limit output tokens Preferred for newer models; some upstreams accept only max_tokens
temperature, top_p Control sampling Reasoning models may ignore or reject some sampling options
stop Set stop sequences Depends on model support
tools, tool_choice Declare tools Both the model and upstream must support tool calling
response_format Request JSON or JSON Schema Requires structured-output support
stream Enable streaming Use the direct API domain and parse SSE
stream_options.include_usage Include usage near the end of a stream Only compatible upstreams return it
reasoning_effort Set reasoning effort Only for reasoning models that accept the field

The gateway can parse these fields without every model accepting them. Keep the original error and request ID, remove optional parameters, then add them back one at a time.

Gemini reasoning levels

The pricing page groups compatibility suffixes into one Gemini model family. For Gemini 3.x SDK requests, prefer the base model ID and send reasoning_effort; -low, -medium, and -high remain accepted compatibility IDs. Gemini 3.8 Flash can select tiers through native thinkingLevel; use exact Argon IDs when a low, medium, or high tier must be guaranteed because the base Argon name can fall back to high through upstream mapping.

After changing a level, start a new request and check the final model, protocol, service group, and charge in Usage. Do not use the pricing family label as a request ID, and do not treat one text reply as proof that tool calling works.

Native Gemini SDK

For native reasoning, image sizes, image editing, or Gemini tool calls, use Gemini GenerateContent with Base URL https://router-api.xiu.ai and x-goog-api-key. Put image size in generationConfig.imageConfig; OpenAI size and quality fields are not equivalent. Verify returned pixels and usage records.

from google import genai

client = genai.Client(
    api_key=os.environ["XIUROUTER_API_KEY"],
    http_options={"base_url": "https://router-api.xiu.ai", "api_version": "v1beta"},
)
response = client.models.generate_content(
    model="gemini-3.1-flash-image",
    contents="Create a square blue robot icon with no text.",
    config={
        "response_modalities": ["TEXT", "IMAGE"],
        "image_config": {"aspect_ratio": "1:1", "image_size": "2K"},
    },
)

Verify the result

  1. Confirm that the program receives complete text, rather than only passing authentication.
  2. In XiuRouter usage logs, check the model, service group, tokens, cost, and status.
  3. Record the x-oneapi-request-id response header for troubleshooting.

Troubleshoot

Symptom Next step
Requests still go to the official provider Check Python’s base_url or JavaScript’s baseURL
401 Invalid token Confirm that the running process can read XIUROUTER_API_KEY
Model unavailable Fetch GET /v1/models again and check the key’s group and model scope
Parameter rejected Keep only model and minimal messages, then retry
Text works but tools or JSON fail Test tools, structured output, and streaming separately

Sources and review date

The Chat Completions and Gemini GenerateContent routes, request fields, and OpenAI/Gemini SDK Base URL settings were reviewed on November 7, 2026. Verify parameter support and returned image dimensions with the actual target model.

Navigation

Enter keywords to search

↑↓ Move↵ OpenEsc Close