Skip to main content

OpenCSG AI Gateway: auto Model Guide

auto is a virtual model provided by OpenCSG AI Gateway. When you set model to auto, the gateway selects a model from those currently available based on the content of each question. The default strategy balances response quality, cost, and speed. You can also use a routing profile to favor lower cost or higher quality, and set a common reasoning effort.

In the examples, $AIGW is the gateway root URL (the SaaS platform's public URL or a self-hosted service URL, such as https://api.example.com, without /v1), and $KEY is your API Key.

1. Send a Request​

Set model to auto. Use the same remaining parameters as when calling a regular model:

curl -i $AIGW/v1/chat/completions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{"model":"auto","messages":[{"role":"user","content":"Help me write quicksort"}]}'

Chat Completions (/v1/chat/completions), Responses (/v1/responses), and Messages (/v1/messages) all support auto. The headers and parameters described in this guide apply to all three APIs.

2. Multi-Turn Conversations​

The gateway assigns a session ID to each conversation and a turn ID to each turn, returning them in the response headers:

Response HeaderMeaningFormat
CSG-Router-Session-IdSession ID identifying a complete conversationses_ + 32 hexadecimal characters
CSG-Router-Turn-IdTurn ID. A turn starts with a new user message and ends with the model's final reply; tool calls, tool result submissions, and retries in between belong to the same turnturn_ + 32 hexadecimal characters

Send these values back in request headers with the same names. This keeps the model unchanged within a turn and lets the gateway select again with context when a new turn starts:

Request TimingHeaders to IncludeGateway Behavior
First message in a conversationNoneSelects a model and returns new session and turn IDs
Subsequent requests within the same turnSession ID + turn IDReuses the model selected for this turn
New user messageSession ID onlySelects a model again with context and returns a new turn ID

For example, include both IDs when submitting tool results:

curl $AIGW/v1/chat/completions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-H "CSG-Router-Session-Id: ses_8f3a..." \
-H "CSG-Router-Turn-Id: turn_1c9e..." \
-d '{"model":"auto","messages":[...],"tools":[...]}'

Important: Both IDs must use the values returned in the response headers. Invalid ID formats, or a turn ID sent without a session ID, are ignored and treated as a new conversation without returning an error. In Agent scenarios, this can cause the model to change mid-loop.

3. Routing Profiles​

A routing profile sets the gateway's preference when selecting a model. Set it through the CSG-Router-Auto-Profile request header. If omitted, the default is balanced.

ProfilePreferenceSuitable Scenarios
economyLower costCost-sensitive tasks that can tolerate a slight reduction in response quality
balancedBalanced (default)Most tasks
qualityHigher qualityTasks with high response quality requirements
curl -i $AIGW/v1/chat/completions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-H "CSG-Router-Auto-Profile: economy" \
-d '{"model":"auto","messages":[{"role":"user","content":"Help me write quicksort"}]}'

Available profiles may differ between platforms. Clients should read the available profiles from the model list rather than hard-code the values above. Call GET $AIGW/v1/models; the model with id set to auto includes the following information:

{
"id": "auto",
"metadata": {
"auto_routing": {
"default_profile": "balanced",
"profiles": [
{"id": "economy", "name": "Economy"},
{"id": "balanced", "name": "Balanced"},
{"id": "quality", "name": "Quality"}
]
}
}
}

Use profiles[].id as the request header value. profiles[].name is the English display name; for localized labels, map display text by id. default_profile is the profile used when the header is omitted.

4. Reasoning Effort​

Models use different parameters to control reasoning, such as thinking.type, enable_thinking, or reasoning_effort. With auto, set reasoning effort using the standard field for your API. The gateway selects only models capable of meeting that effort and translates the setting into the parameters required by the selected model.

APIFieldExample
Chat Completionsreasoning_effort"reasoning_effort": "medium"
Responsesreasoning.effort"reasoning": {"effort": "medium"}
Messagesoutput_config.effort"output_config": {"effort": "medium"}
ValueMeaning
OmittedUses the selected model's default reasoning behavior
noneDisables reasoning; selects only models that support disabling it
minimal, low, medium, high, xhigh, max (in ascending order)Enables reasoning; selects only models capable of meeting that effort

Values are case-insensitive. Use the corresponding field listed above for each API. If you also provide model-specific parameters such as thinking or enable_thinking that conflict with that field, the request is rejected.

curl -i $AIGW/v1/chat/completions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{"model":"auto","reasoning_effort":"medium","messages":[{"role":"user","content":"How many integers from 1 to 1000 are divisible by 7 but not by 5?"}]}'

Effort Mapping​

Models offer different reasoning effort levels. The gateway uses the lowest supported level that is not below the requested effort. For example, if you request medium but the selected model offers only low and high, the gateway uses high. The actual effort may therefore exceed the requested value, increasing reasoning token usage and response time.

Effort levels represent relative intensity, not a fixed token count. Different models also have different reasoning capabilities at the same effort level.

5. Combine a Profile and Reasoning Effort​

Reasoning effort is a filter, while the routing profile is a selection preference. The gateway first filters for models capable of meeting the requested effort, then selects among them according to the profile. For example, economy + high favors lower-cost models among those supporting high reasoning effort.

Adjust the routing profile and reasoning effort at the start of a new turn. Every request within the same turn must include the same profile and effort as that turn's first request; omitting CSG-Router-Auto-Profile means using the default profile. Requests that change the routing profile within a turn are rejected.

curl -i $AIGW/v1/chat/completions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-H "CSG-Router-Auto-Profile: economy" \
-d '{"model":"auto","reasoning_effort":"high","messages":[{"role":"user","content":"Prove that the square root of 2 is irrational"}]}'

6. Complete Example​

This Python example uses the OpenAI SDK. Each conversation has its own AutoConversation object, which automatically saves and sends back the session and turn IDs.

import os
from openai import OpenAI

client = OpenAI(base_url=os.environ["AIGW"] + "/v1", api_key=os.environ["KEY"])


class AutoConversation:
def __init__(self):
self.sid = self.tid = None

def call(self, messages, new_turn, profile=None, effort=None):
headers = {}
if self.sid:
headers["CSG-Router-Session-Id"] = self.sid
if not new_turn and self.tid:
headers["CSG-Router-Turn-Id"] = self.tid
if profile:
headers["CSG-Router-Auto-Profile"] = profile

extra = {"reasoning_effort": effort} if effort else {}
raw = client.chat.completions.with_raw_response.create(
model="auto", messages=messages, extra_headers=headers, **extra)
self.sid = raw.headers.get("CSG-Router-Session-Id") or self.sid
self.tid = raw.headers.get("CSG-Router-Turn-Id") or self.tid
return raw.parse()


conv = AutoConversation()
# New user message: conv.call(msgs, new_turn=True, profile="economy", effort="medium")
# Tool results: conv.call(msgs, new_turn=False, profile="economy", effort="medium")

Connect and Call Models · Routing and Reliability · Performance and Cost Optimization