Create Trace
Send a trace to the Costrace backend.Headers
Request Body
LLM provider:
openai, anthropic, or geminiModel name (e.g.,
gpt-4o, claude-sonnet-4-20250514)Number of input/prompt tokens
Number of output/completion tokens
Request latency in milliseconds
Calculated cost in USD
Your Costrace API key (used to identify the trace source)
Request status:
success or errorError message (only if
status is error)Example Request
Response
ok if the trace was accepted202 Accepted
Error Responses
400 Bad Request
Invalid request body:401 Unauthorized
Invalid API key:Cost Calculation
The SDK automatically calculates costs based on current pricing. If you’re sending traces manually, use this formula:Example Pricing (as of Feb 2026)
| Provider | Model | Input ($/1M) | Output ($/1M) |
|---|---|---|---|
| OpenAI | gpt-4o | $2.50 | $10.00 |
| OpenAI | gpt-4o-mini | $0.15 | $0.60 |
| Anthropic | claude-opus-4-6 | $5.00 | $25.00 |
| Anthropic | claude-haiku-4-5 | $1.00 | $5.00 |
| Gemini | gemini-2.0-flash | $0.10 | $0.40 |
Pricing is subject to change by providers. The SDK includes up-to-date pricing tables.
Best Practices
Use the SDK
The SDKs handle trace creation, cost calculation, and sending automatically. Manual API calls are only needed for:- Custom integrations
- Non-supported languages
- Debugging