Skip to main content
POST
Turns API

Turns API

Turns represent individual conversation exchanges between a user and your agent. Each turn captures the complete interaction context including input, output, state changes, and reasoning.

Why Log Turns?

Turns provide:
  • Complete audit trail of all agent decisions
  • Debugging capability (replay exact conversations)
  • Analytics (measure success rates, latency, tool usage)
  • Rollback points (revert to any previous turn)

Add Turn

POST /v1/sessions/{session_id}/turns Logs a new conversation turn. This is typically called after your agent generates a response.

Path Parameters

Request Body

Input Object

Output Object

Response

Example


Get Turn

GET /v1/sessions/{session_id}/turns/{turn_id} Retrieves a specific turn by ID.

Path Parameters

Example


List Turns

GET /v1/sessions/{session_id}/turns Lists all turns for a session, ordered by creation time (newest first).

Path Parameters

Query Parameters

Example


Common Use Cases

1. Logging Tool Calls

Track when your agent uses external tools:

2. Logging Errors

Track when things go wrong:

3. State Tracking

Log state changes with each turn:

4. Analytics

Analyze agent performance:

Best Practices

✅ Do This

  • Always include reasoning (invaluable for debugging)
  • Log metadata (tool names, latency, model used, etc.)
  • Log errors (don’t just catch and ignore)
  • Use structured types ("text", "tool_call", "error")
  • Include state snapshots for critical turns

❌ Avoid This

  • Don’t skip turn logging (you’ll regret it when debugging)
  • Don’t log sensitive data in content (use encrypted metadata)
  • Don’t log every internal step (only user-facing interactions)
  • Don’t forget to paginate when listing turns

Turn Types Reference

Input Types

Output Types


Error Responses


Next Steps


Key Takeaway: Turns are your time machine. Log everything, and you can replay any conversation to debug production issues.