Find a model

Browse the full catalog →

Batch cuts eligible native OpenAI and Parasail item prices by 50% without changing models. Move about 53% of requests from Claude Sonnet 5.5 to GPT-6 Luna to halve the example inference bill; the code change is the base URL and model name, using your TrustedRouter credential.

Guide checked . The priced workload is 10,000 requests with 4,000 input and 1,000 output tokens each, using OpenAI for the small model and Anthropic for the premium model. These calculations compare TrustedRouter inference bills.

Change the base URL and model in the OpenAI Python SDK

First, keep the same model and OpenAI SDK request shape; configure the TrustedRouter endpoint and key.

Before: OpenAI

import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.chat.completions.create(
    model="gpt-5.4-mini",
    messages=[{"role": "user", "content": "Summarize this document."}],
)
print(response.choices[0].message.content)

After: TrustedRouter, same model

import os
from openai import OpenAI

client = OpenAI(base_url="https://api-azure.trustedrouter.com/v1",
                api_key=os.environ["TRUSTEDROUTER_API_KEY"])
response = client.chat.completions.create(
    model="gpt-5.4-mini",
    messages=[{"role": "user", "content": "Summarize this document."}],
)
print(response.choices[0].message.content)

Second, change model to openai/gpt-6-luna for the smaller model. Create a key at Console → API Keys. See OpenAI SDK migration for provider-specific compatibility.

This allocation sends 80% of requests to GPT-6 Luna and the remaining 20% to Claude Sonnet 5.5; repeat the ten-request cycle for the example workload.

import os
from openai import OpenAI

client = OpenAI(base_url="https://api-azure.trustedrouter.com/v1",
                api_key=os.environ["TRUSTEDROUTER_API_KEY"])
messages = [{"role": "user", "content": "Summarize this document."}]
for request_index in range(10):
    model = ("openai/gpt-6-luna" if request_index % 10 < 8
             else "anthropic/claude-sonnet-5.5")
    response = client.chat.completions.create(model=model, messages=messages)
    print(response.choices[0].message.content)

Cost levers with numbers

Sending 80% of the example workload to GPT-6 Luna and 20% to Claude Sonnet 5.5 costs $45.58 instead of $189.90.

LeverWhat you changeSavingCatch
Cheaper model for easy tasks80/20 small/premium allocation$144.32 (76%)Validate task quality; these are equal-token assumptions.
BatchSubmit work that can wait to the native Batch path50% on eligible native OpenAI and Parasail itemsNative execution must be enabled; ordinary fallback uses normal prices.
Prompt cachingReuse eligible input with GPT-6 Luna on OpenAI90% on cached input: $0.01055 versus $0.1055 per millionOnly cache hits get the read rate; output cost remains.
provider.sort: "price"Prefer lower-priced routes for DeepSeek V4.1 FlashUp to 96% between the highest and lowest priced route for this model todayYour saving is against the route you use now; route availability, privacy and capability filters still apply.

DeepSeek V4.1 Flash has 21 prepaid provider routes. Ranked by input plus output price, the lowest is Engy at $0.03165 input / $0.1266 output per million tokens; the highest is IO Intelligence at $0.865311 / $3.537837. These TrustedRouter retail rates include the standard markup and use the 4,000-token context tier. Prices collected ; IO Intelligence: ; all provider routes and limits.

{"model":"deepseek/deepseek-v4.1-flash","messages":[{"role":"user","content":"Summarize this paragraph."}],"provider":{"sort":"price"},"max_tokens":256}

The trustedrouter/cheap alias also offers a paid low-cost pool; the exact saving depends on the selected model and fallback.

{"model":"trustedrouter/cheap","messages":[{"role":"user","content":"Draft a short subject line."}],"max_tokens":64}

Route to a cheaper model and fall back to a premium one

Gateway fallback on serving failure

Put the cheaper model in model and the premium model in models; TrustedRouter tries them in order.

{"model":"openai/gpt-6-luna","models":["anthropic/claude-sonnet-5.5"],"messages":[{"role":"user","content":"Explain this function."}],"max_tokens":256}

Fallback handles serving failures such as a provider being unavailable, not answer quality. The serving model and route determine the charge; inspect the response's model and trustedrouter.routing metadata and known usage cost. See failover and routing controls.

Application escalation on answer quality

Validate the small model's answer and call the premium model if it fails your check.

import json
import os
from openai import OpenAI
client = OpenAI(base_url="https://api-azure.trustedrouter.com/v1", api_key=os.environ["TRUSTEDROUTER_API_KEY"])
messages = [{"role": "user", "content": (
    'Extract the support ticket as JSON with keys "issue" and "priority": '
    'Checkout returns a 500 error for every customer; sales are blocked.'
)}]
def ask(model):
    return client.chat.completions.create(model=model, messages=messages)
def valid_ticket(reply):
    try:
        ticket = json.loads(reply or "")
    except json.JSONDecodeError:
        return False
    return (isinstance(ticket, dict)
            and {"issue", "priority"}.issubset(ticket)
            and isinstance(ticket["issue"], str) and bool(ticket["issue"].strip())
            and ticket["priority"] in ("low", "medium", "high", "urgent"))
response = ask("openai/gpt-6-luna")
if not valid_ticket(response.choices[0].message.content):
    response = ask("anthropic/claude-sonnet-5.5")
print(response.choices[0].message.content)

The application parses JSON and checks the required ticket fields; a parsing or field check failure triggers the premium call. Expected cost = small-model cost + escalation share times premium-model cost. At a 20% escalation share, every request pays for GPT-6 Luna and that share also pays for Claude Sonnet 5.5: $9.50 + 20% × $189.90 = $47.48 for the example workload. Unlike allocation, escalation pays for both calls on retried tasks.

Reuse stable prefixes with prompt caching

Eligible cache reads for GPT-6 Luna on OpenAI cost $0.01055 per million input tokens versus $0.1055 for uncached input, a 90% input saving.

{"model":"openai/gpt-6-luna","session_id":"cost-evaluation-session","messages":[{"role":"system","content":"Your stable context goes here."},{"role":"user","content":"Summarize section one."}],"provider":{"only":["openai"],"allow_fallbacks":false},"max_tokens":256}

Replace the placeholder: use a repeated prefix long enough for the provider's cache rules. See prompt caching.

Use Batch for work that can wait

Eligible native OpenAI and Parasail Batch items receive their published 50% discount when native execution is enabled.

This is a chat item body; supply openai/gpt-6-luna as the model in the complete Batch submission and polling example at /api/beta/batches.

{"messages":[{"role":"user","content":"Summarize this document."}],"max_tokens":256}

Unsupported or failed native items can use ordinary fallback at normal prices. See the Batch guide for retention.

Cap spend

Create a dedicated key with a $5.00 daily and $100.00 monthly limit.

Send this body to POST https://trustedrouter.com/v1/keys with a management credential:

{"name":"Cost evaluation agent","limit_daily":5,"limit_monthly":100,"budget_strict":true,"budget_alert_only":false}

Strict mode counts outstanding estimated costs and is not an absolute final-charge ceiling. See per-key controls.

For an existing provider account, register its credential through BYOK, then select that billing path:

{"model":"openai/gpt-6-luna","messages":[{"role":"user","content":"Reply with PONG."}],"provider":{"only":["openai"],"allow_fallbacks":false,"usage":"byok"},"max_tokens":16}

BYOK re-bills inference to your provider account. Compare fees and request costs and configure OpenCode.

Questions

How can I cut AI API costs without rewriting code?

Keep the OpenAI SDK request shape, configure the TrustedRouter base URL and credential, and choose a cheaper model for suitable tasks. Compare the 80/20 model allocation and eligible 50% native Batch discount.

How do I route to cheaper models and fall back to premium ones?

Put the cheaper model in model and the premium model in models. TrustedRouter tries them in order for serving failures. Quality escalation needs application validation and can bill both calls.

Workspace access

Sign in

Choose a sign in method to access your TrustedRouter workspace.

New to TrustedRouter?

By continuing you agree to the terms of service and privacy policy.