OpenRouter

Automatic compression for OpenRouter API calls.

OpenRouter uses the OpenAI-compatible API, so you can use the same withCompression() wrapper. Just point the client at OpenRouter's base URL.

Setup

from openai import OpenAI
from thetokencompany.openai import with_compression

# OpenRouter uses the OpenAI-compatible API
client = with_compression(
OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="YOUR_OPENROUTER_API_KEY",
),
compression_api_key="ttc-...",
)

response = client.chat.completions.create(
model="openai/gpt-5.4",
messages=[
{"role": "user", "content": "Your long prompt text here..."},
],
)

print(response.choices[0].message.content)
Tip
This works with any OpenAI-compatible provider - Together AI, Groq, Fireworks, and others. Just change the baseURL.