App ID

Tag compression requests with an application identifier for per-app usage tracking.

Use app_id to tag compression requests with an identifier for the application or service making the call. This lets you break down usage and costs per application on the dashboard.

Client-level

Set app_id when creating the client. Every request automatically includes it.

from thetokencompany import TheTokenCompany

# Set on the client — every compress() call includes this app_id
client = TheTokenCompany(api_key="ttc-...", app_id="my-chatbot")

result = client.compress("Your long prompt text...", aggressiveness=0.2)

Per-request override

Pass app_id directly to compress() to override the client-level value for a single call.

client = TheTokenCompany(api_key="ttc-...", app_id="default-app")

# This request is tagged "default-app"
client.compress("Hello...", aggressiveness=0.2)

# This request is tagged "search-agent" (overrides client-level)
client.compress("Search results...", aggressiveness=0.4, app_id="search-agent")
Info
If both client-level and per-request app_id are set, the per-request value wins.

With wrappers

All withCompression() wrappers accept app_id. It is passed to the internal client, so every compression call made by the wrapper is tagged automatically.

from openai import OpenAI
from thetokencompany.openai import with_compression

client = with_compression(
OpenAI(api_key="YOUR_OPENAI_API_KEY"),
compression_api_key="ttc-...",
app_id="my-chatbot",
)

# All compression requests are tagged "my-chatbot"
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Your prompt..."}],
)

Vercel AI SDK

import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
import { withCompression } from "the-token-company/ai-sdk";

const model = withCompression(openai("gpt-4o"), {
compressionApiKey: "ttc-...",
appId: "my-chatbot",
});

const { text } = await generateText({
model,
messages: [{ role: "user", content: "Your prompt..." }],
});

When to use

  • Multi-app setups — share one API key across services but track usage per app
  • Cost attribution — break down token savings by chatbot, agent, pipeline, or feature
  • Debugging — identify which application is generating specific traffic patterns