Create Trace
Send a trace to the Costrace backend.Headers
Request Body
string
required
LLM provider:
openai, anthropic, or geministring
required
Model name (e.g.,
gpt-4o, claude-sonnet-4-20250514)integer
required
Number of input/prompt tokens
integer
required
Number of output/completion tokens
integer
required
Request latency in milliseconds
number
required
Calculated cost in USD
string
required
Your Costrace API key (used to identify the trace source)
string
required
Request status:
success or errorstring
Error message (only if
status is error)Example Request
Response
string
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)
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