From d063b8a832c348219e4eb89b46de061bc6062d27 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 02:50:18 +0000 Subject: [PATCH 1/3] docs: improve JWT token retrieval documentation - Add get_session_jwt() documentation in sdk-reference.mdx - Add Session Authentication section in sessions.mdx - Document JWT token retrieval process Co-Authored-By: Alex Reibman --- docs/v1/concepts/sessions.mdx | 20 ++++++++++++++++++-- docs/v1/usage/sdk-reference.mdx | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/v1/concepts/sessions.mdx b/docs/v1/concepts/sessions.mdx index 68beaf02..ced2c25e 100644 --- a/docs/v1/concepts/sessions.mdx +++ b/docs/v1/concepts/sessions.mdx @@ -94,8 +94,24 @@ agentops.init(inherited_session_id=) Both processes will now contribute data to the same session. +## Session Authentication +Each session is assigned a unique JWT token that can be used to authenticate session-specific API requests. You can retrieve the JWT token for a session using `agentops.get_session_jwt()`: + +```python +import agentops + +# Get JWT for current session +session = agentops.init() +jwt_token = agentops.get_session_jwt() + +# Or get JWT for a specific session +jwt_token = agentops.get_session_jwt(session_id="your-session-id") +``` + +This JWT token is required alongside your API key when making session-specific API requests. + ## 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. @@ -127,4 +143,4 @@ be applied. You can also apply different configuration options when you start a [Configuration](/v1/usage/sdk-reference/#configuration) object. - \ No newline at end of file + diff --git a/docs/v1/usage/sdk-reference.mdx b/docs/v1/usage/sdk-reference.mdx index 62b11c9f..ad1929ad 100644 --- a/docs/v1/usage/sdk-reference.mdx +++ b/docs/v1/usage/sdk-reference.mdx @@ -101,6 +101,20 @@ Retrieve the API key used by the client. --- +### `get_session_jwt()` + +Retrieve the JWT token for the current or specified session. + +**Parameters**: + +- `session_id` (str, optional): The ID of the session to get the JWT for. If not provided, uses the current session. + +**Returns**: + +- JWT token as a string. + +--- + ### `set_parent_key()` Set the parent API key which has visibility over projects it is a parent of. From 3172c6e81a549b193828d462221ab08bb6dd3013 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 03:39:06 +0000 Subject: [PATCH 2/3] docs: update session data export documentation Co-Authored-By: Alex Reibman --- docs/v1/concepts/sessions.mdx | 66 ++++++++++++++++++++++++++++----- docs/v1/usage/sdk-reference.mdx | 12 ++---- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/docs/v1/concepts/sessions.mdx b/docs/v1/concepts/sessions.mdx index ced2c25e..5ca42010 100644 --- a/docs/v1/concepts/sessions.mdx +++ b/docs/v1/concepts/sessions.mdx @@ -94,21 +94,67 @@ agentops.init(inherited_session_id=) Both processes will now contribute data to the same session. -## Session Authentication -Each session is assigned a unique JWT token that can be used to authenticate session-specific API requests. You can retrieve the JWT token for a session using `agentops.get_session_jwt()`: +## 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. -```python -import agentops +### Authentication +All data export requests require two headers: +- `X-Agentops-Api-Key`: Your AgentOps API key +- `Authorization`: Bearer token from session initialization -# Get JWT for current session -session = agentops.init() -jwt_token = agentops.get_session_jwt() +### Available Endpoints -# Or get JWT for a specific session -jwt_token = agentops.get_session_jwt(session_id="your-session-id") +#### Get Session Statistics +```http +GET /v2/sessions//stats ``` -This JWT token is required alongside your API key when making session-specific API requests. +Returns statistics for the specified session including: +- Event counts +- Duration +- Costs +- Token usage +- Other session metrics + +#### Export Complete Session Data +```http +GET /v2/sessions//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" +# Bearer token from session initialization +bearer_token = "your-bearer-token" +session_id = "your-session-id" + +headers = { + "X-Agentops-Api-Key": api_key, + "Authorization": f"Bearer {bearer_token}" +} + +# 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()`. diff --git a/docs/v1/usage/sdk-reference.mdx b/docs/v1/usage/sdk-reference.mdx index ad1929ad..12415814 100644 --- a/docs/v1/usage/sdk-reference.mdx +++ b/docs/v1/usage/sdk-reference.mdx @@ -101,22 +101,16 @@ Retrieve the API key used by the client. --- -### `get_session_jwt()` +### `set_parent_key()` -Retrieve the JWT token for the current or specified session. +Set the parent API key which has visibility over projects it is a parent of. **Parameters**: -- `session_id` (str, optional): The ID of the session to get the JWT for. If not provided, uses the current session. - -**Returns**: - -- JWT token as a string. +- `parent_key` (str): The API key of the parent organization to set. --- -### `set_parent_key()` - Set the parent API key which has visibility over projects it is a parent of. **Parameters**: From 4f2804624e7be6eb71ac0a4ec29ddede6d4ff127 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 05:45:53 +0000 Subject: [PATCH 3/3] docs: simplify session data export authentication to use only API key Co-Authored-By: Alex Reibman --- docs/v1/concepts/sessions.mdx | 8 ++------ docs/v1/usage/sdk-reference.mdx | 8 -------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/docs/v1/concepts/sessions.mdx b/docs/v1/concepts/sessions.mdx index 5ca42010..ec98cb7f 100644 --- a/docs/v1/concepts/sessions.mdx +++ b/docs/v1/concepts/sessions.mdx @@ -98,9 +98,8 @@ Both processes will now contribute data to the same session. 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 two headers: +All data export requests require a single header: - `X-Agentops-Api-Key`: Your AgentOps API key -- `Authorization`: Bearer token from session initialization ### Available Endpoints @@ -136,13 +135,10 @@ import requests # Your AgentOps API key api_key = "your-api-key" -# Bearer token from session initialization -bearer_token = "your-bearer-token" session_id = "your-session-id" headers = { - "X-Agentops-Api-Key": api_key, - "Authorization": f"Bearer {bearer_token}" + "X-Agentops-Api-Key": api_key } # Get session stats diff --git a/docs/v1/usage/sdk-reference.mdx b/docs/v1/usage/sdk-reference.mdx index 12415814..62b11c9f 100644 --- a/docs/v1/usage/sdk-reference.mdx +++ b/docs/v1/usage/sdk-reference.mdx @@ -111,14 +111,6 @@ Set the parent API key which has visibility over projects it is a parent of. --- -Set the parent API key which has visibility over projects it is a parent of. - -**Parameters**: - -- `parent_key` (str): The API key of the parent organization to set. - ---- - ### `stop_instrumenting()` Stops instrumenting LLM calls. This is typically used by agent frameworks (i.e., [CrewAI](/v1/integrations/crewai) and