Application observability
Read response usage, inspect compression metrics, and tag application requests.
Track application requests in code and inspect them in the console. For console dashboards and investigation, see Observability.
Token Usage Tracking
The native Edgee SDK exposes response usage for tracking tokens and costs. The examples below assume an initialized edgee client; see your language’s SDK guide for setup.
const response = await edgee.send({
model: 'gpt-5.2',
input: 'Your prompt here',
});
console.log(response.usage.prompt_tokens); // Compressed input tokens
console.log(response.usage.completion_tokens); // Output tokens
console.log(response.usage.total_tokens); // Total for billing
// Compression savings (when applied)
if (response.compression) {
console.log(response.compression.saved_tokens); // Tokens saved by compression
console.log(response.compression.cost_savings); // Cost savings in micro-units (e.g. 27000 = $0.027)
console.log(response.compression.reduction); // Percentage reduction (e.g. 18 = 18%)
console.log(response.compression.time_ms); // Time taken for compression in milliseconds
}
Track usage by:
- Model (GPT-5.2 vs Claude vs Gemini)
- Project or application
- Environment (production vs staging)
- User or tenant (for multi-tenant apps)
- Time period (daily, weekly, monthly)
Request Tags for Analytics
Tags allow you to categorize and label requests for filtering and grouping in your analytics dashboard. Add tags to track requests by environment, feature, user, team, or any custom dimension.
Using tags in native SDKs:
import Edgee from 'edgee';
const edgee = new Edgee("your-api-key");
const response = await edgee.send({
model: 'gpt-5.2',
input: {
messages: [{ role: 'user', content: 'Hello!' }],
tags: ['production', 'chat-feature', 'user-123', 'team-backend']
}
});
Using tags with OpenAI/Anthropic SDKs via headers:
If you're using the OpenAI or Anthropic SDKs with Edgee, add tags via the x-edgee-tags header (comma-separated):
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://edgee.io/v1",
apiKey: process.env.EDGEE_API_KEY,
defaultHeaders: {
"x-edgee-tags": "production,chat-feature,user-123,team-backend"
}
});
Common tagging strategies:
Environment tagging
Tag by environment: production, staging, development
Feature tagging
Tag by feature: chat, summarization, code-generation, rag-qa
User/tenant tagging
Track per-user or per-tenant usage: user-123, tenant-acme, customer-xyz
Team tagging
Organize by team: team-backend, team-frontend, team-data
Compression Metrics
See exactly how much token compression is saving you on every request:
const response = await edgee.send({
model: 'gpt-5.2',
input: {
messages, // a conversation that includes tool calls and their results
tool_result_trimming: true,
},
});
// Compression details
if (response.compression) {
console.log(response.compression.saved_tokens); // Tokens saved
console.log(response.compression.cost_savings); // Cost savings in micro-units (e.g. 27000 = $0.027)
console.log(response.compression.reduction); // Percentage reduction (e.g. 18 = 18%)
console.log(response.compression.time_ms); // Time taken for compression in milliseconds
}
Reading the compression block
The native Edgee SDK exposes a compression block when compression details are returned. Do not assume every provider-compatible response includes this extension; use the console to inspect those requests.
const response = await edgee.send({
model: 'gpt-5.2',
input: 'Long prompt with lots of context...',
});
if (response.compression) {
console.log(response.compression.saved_tokens); // e.g. 450
console.log(response.compression.cost_savings); // micro-units (1_000_000 = $1.00)
console.log(response.compression.reduction); // percentage, e.g. 18 → 18%
console.log(response.compression.time_ms); // ms spent on compression
}
Field reference:
| Field | Type | Meaning |
|---|---|---|
saved_tokens | integer | Input tokens removed (original count minus compressed count). |
cost_savings | integer | Estimated cost savings in micro-units. Divide by 1_000_000 for USD. |
reduction | number | Percentage reduction in input tokens. 18 → 18%. |
time_ms | integer | Wall-clock time spent on compression. |
The usage.prompt_tokens field on the same response reflects the compressed count actually billed by the provider, not the original input.