Tracing via API
Tracing to Athina can be done via simple API requests.
Getting Started
You will need your athina API key from the Athina dashboard to do tracing via API. All API requests require authentication using an API key. Include your API key in the header of each request:
Requirements
span_type: "generation"
.
Traces without any generation spans will be stored but won’t appear in the UI currently.Base URL
The base URL is: https://api.athina.ai
for all the following endpoints.
Endpoints
1. Create Trace
Create a new trace for your application.
- URL:
/api/v1/trace/
- Method:
POST
- Body:
- Response: Returns the created trace object with a unique
id
.
2. Get Trace
Retrieve a trace by its ID.
- URL:
/api/v1/trace/{trace_id}
- Method:
GET
- Response: Returns the trace object with all its spans.
3. Update Trace
Update an existing trace.
- URL:
/api/v1/trace/{trace_id}
- Method:
PUT
- Body:
- Response: Returns the updated trace object.
4. Create Span
Create a new span within a trace.
- URL:
/api/v1/trace/{trace_id}/spans
- Method:
POST
- Body:
- Response: Returns the created span object.
5. Get Span
Retrieve a span by its ID within a trace.
- URL:
/api/v1/trace/{trace_id}/spans/{span_id}
- Method:
GET
- Response: Returns the span object.
6. Update Span
Update an existing span within a trace.
- URL:
/api/v1/trace/{trace_id}/spans/{span_id}
- Method:
PUT
- Body:
- Response: Returns the updated span object.
Object Structures
Trace Object
Span Object
Full Example: Creating a Trace with Spans
This example demonstrates how to create a trace for a hypothetical conversation with an AI assistant, including multiple spans for different parts of the interaction.
Step 1: Create a Trace
First, let’s create a trace for the entire conversation.
Request:
Response:
Step 2: Create a Span for User Input
Now, let’s create a span for the user’s input.
Request:
Response:
Step 3: Create a Span for AI Processing
Next, let’s create a span for the AI’s processing of the user’s input.
Request:
Response:
Step 4: Update the Trace to Complete It
Finally, let’s update the trace to mark it as completed.
Request:
Response:
Conclusion
By following this example and adapting it to your specific use case, you can effectively use the Athina Tracing API to capture detailed information about your AI application’s performance and behavior. This data can be invaluable for monitoring, debugging, and optimizing your AI-powered systems.
Remember to handle errors appropriately, respect rate limits, and follow best practices when implementing this in your production environment.