Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add session data export endpoint documentation #594

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions docs/v1/concepts/sessions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,66 @@ agentops.init(inherited_session_id=<id>)

Both processes will now contribute data to the same session.

## Session Data Export
AgentOps provides REST endpoints to export your session data and statistics. These endpoints allow you to retrieve detailed information about your sessions programmatically.

### Authentication
All data export requests require a single header:
- `X-Agentops-Api-Key`: Your AgentOps API key

### Available Endpoints

#### Get Session Statistics
```http
GET /v2/sessions/<session_id>/stats
```

Returns statistics for the specified session including:
- Event counts
- Duration
- Costs
- Token usage
- Other session metrics

#### Export Complete Session Data
```http
GET /v2/sessions/<session_id>/export
```

Returns comprehensive session data including:
- Session metadata
- Statistics
- All recorded events:
- Actions
- LLM calls
- Tool usage
- Errors

### Example Usage
```python
import requests

# Your AgentOps API key
api_key = "your-api-key"
session_id = "your-session-id"

headers = {
"X-Agentops-Api-Key": api_key
}

# Get session stats
stats_url = f"https://api.agentops.ai/v2/sessions/{session_id}/stats"
stats_response = requests.get(stats_url, headers=headers)
stats = stats_response.json()

# Export complete session data
export_url = f"https://api.agentops.ai/v2/sessions/{session_id}/export"
export_response = requests.get(export_url, headers=headers)
session_data = export_response.json()
```

## Session Analytics
You can retrieve the analytics for a session by calling `session.get_analytics()`.
You can retrieve the analytics for a session by calling `session.get_analytics()`.

The example below shows how to record events and retrieve analytics.

Expand Down Expand Up @@ -127,4 +185,4 @@ be applied. You can also apply different configuration options when you start a
[Configuration](/v1/usage/sdk-reference/#configuration) object.

<script type="module" src="/scripts/github_stars.js"></script>
<script type="module" src="/scripts/adjust_api_dynamically.js"></script>
<script type="module" src="/scripts/adjust_api_dynamically.js"></script>