For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DashboardSign Up
  • Getting Started
    • Welcome
    • Quick Start
    • Authentication
  • Native Mode
    • Overview
    • OpenAI
    • Anthropic
    • Gemini
  • Unified Mode
    • Overview
    • Python
    • TypeScript
    • cURL
  • Platform
    • Key Management
    • Rate Limits & Budgets
    • Usage & Billing
    • Error Reference
  • API Reference
DashboardSign Up
On this page
  • Setup
  • Basic chat
  • OpenAI
  • Anthropic
  • Gemini
  • Streaming
  • System messages
  • Tool calling
  • Multi-turn conversation
  • Switching providers
Unified Mode

Python (Unified Mode)

Call any provider using the OpenAI Python SDK
Was this page helpful?
Edit this page
Previous

TypeScript (Unified Mode)

Call any provider using the OpenAI Node.js SDK
Next
Built with

Setup

$pip install openai
1from openai import OpenAI
2
3client = OpenAI(
4 api_key="sk-proxy-YOUR_KEY_HERE",
5 base_url="https://api.trygateway.ai/v1"
6)

Basic chat

OpenAI

1response = client.chat.completions.create(
2 model="openai/gpt-4o",
3 messages=[{"role": "user", "content": "Hello!"}]
4)
5print(response.choices[0].message.content)

Anthropic

1response = client.chat.completions.create(
2 model="anthropic/claude-sonnet-4-6",
3 messages=[{"role": "user", "content": "Hello!"}]
4)
5print(response.choices[0].message.content)

Gemini

1response = client.chat.completions.create(
2 model="google/gemini-2.5-flash",
3 messages=[{"role": "user", "content": "Hello!"}]
4)
5print(response.choices[0].message.content)

Streaming

Works identically across all providers:

1stream = client.chat.completions.create(
2 model="anthropic/claude-sonnet-4-6",
3 messages=[{"role": "user", "content": "Write a short poem about code."}],
4 stream=True
5)
6
7for chunk in stream:
8 content = chunk.choices[0].delta.content
9 if content:
10 print(content, end="")

System messages

1response = client.chat.completions.create(
2 model="anthropic/claude-sonnet-4-6",
3 messages=[
4 {"role": "system", "content": "You are a senior software engineer. Be concise."},
5 {"role": "user", "content": "What's the difference between a mutex and a semaphore?"}
6 ]
7)

System messages are translated to each provider’s native format automatically (e.g., Anthropic’s system parameter, Gemini’s system_instruction).

Tool calling

The same tool definition works for every provider:

1tools = [
2 {
3 "type": "function",
4 "function": {
5 "name": "get_weather",
6 "description": "Get weather for a city",
7 "parameters": {
8 "type": "object",
9 "properties": {
10 "city": {"type": "string"}
11 },
12 "required": ["city"]
13 }
14 }
15 }
16]
17
18response = client.chat.completions.create(
19 model="google/gemini-2.5-flash",
20 messages=[{"role": "user", "content": "What's the weather in Paris?"}],
21 tools=tools,
22 tool_choice="auto"
23)
24
25# Standard OpenAI tool_calls format, regardless of provider
26tool_call = response.choices[0].message.tool_calls[0]
27print(f"{tool_call.function.name}({tool_call.function.arguments})")

Multi-turn conversation

1messages = [
2 {"role": "system", "content": "You are a helpful math tutor."},
3 {"role": "user", "content": "What is a derivative?"}
4]
5
6response = client.chat.completions.create(
7 model="openai/gpt-4o",
8 messages=messages
9)
10
11messages.append(response.choices[0].message)
12messages.append({"role": "user", "content": "Can you give me an example?"})
13
14response = client.chat.completions.create(
15 model="openai/gpt-4o",
16 messages=messages
17)
18
19print(response.choices[0].message.content)

Switching providers

The power of unified mode: swap providers by changing one string. Your code, prompts, tools, and response handling all stay the same.

1models = [
2 "openai/gpt-4o",
3 "anthropic/claude-sonnet-4-6",
4 "google/gemini-2.5-flash",
5]
6
7for model in models:
8 response = client.chat.completions.create(
9 model=model,
10 messages=[{"role": "user", "content": "What is 2+2?"}]
11 )
12 print(f"{model}: {response.choices[0].message.content}")