Skip to content

Commit 4ab71d4

Browse files
reference Gateway in explorer docs
1 parent 53a2204 commit 4ab71d4

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

docs/explorer/index.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ title: Overview
66

77
<div class='subtitle'>Learn how to upload your AI agent traces to the Invariant Explorer</div>
88

9-
This quickstart guide will walk you through the process of setting up the Invariant SDK to upload your AI agent traces to the <img class='inline-invariant' src="assets/logo.svg"/> [Invariant Explorer](https://explorer.invariantlabs.ai).
9+
This quickstart guide will walk you through the process of setting up the Invariant SDK to upload your AI agent traces to the <img class='inline-invariant' src="assets/logo.svg"/> [Invariant Explorer](https://explorer.invariantlabs.ai).
1010

1111
You can use Explorer to visualize, analyze, and collaborate on your AI agent traces, as well as compare them with other agents and models.
1212

1313
![Explorer](./assets/explorer-overview.png)
14+
1415
<center>Viewing agent traces in Explorer</center>
1516

1617
## 1. Create an Explorer Account
@@ -29,17 +30,57 @@ Make note of your API key, as you will need it to authenticate your uploads. If
2930
export INVARIANT_API_KEY=<your-api-key>
3031
```
3132

32-
## 3. Install the Invariant SDK
33+
## 3. Upload Your Traces
34+
35+
You can now upload your AI agent traces to the Invariant Explorer.
36+
37+
For this, you have two options: (A) Automatic upload via the Invariant Gateway, or (B) manual upload via the Invariant SDK.
38+
39+
### Option A: Using Invariant Gateway for Automatic Tracing
40+
41+
The recommended way for frictionless ingestion of your traces is to use the [Invariant Gateway](../gateway/index.md). This is a hosted service that automatically ingests your traces and makes them available in Explorer.
42+
43+
To do so, Gateway proxies your LLM provider like OpenAI (forwarding the request and response behind the scenes) and then extracts the relevant information from the LLM responses to create a trace, automatically making it available in Explorer.
44+
45+
```python hl_lines="3 8"
46+
http_client = Client(
47+
headers={
48+
"Invariant-Authorization": "Bearer {your-invariant-api-key}"
49+
},
50+
)
51+
openai = OpenAI(
52+
http_client=http_client,
53+
base_url="https://explorer.invariantlabs.ai/api/v1/gateway/my-first-dataset/openai",
54+
)
55+
56+
result = openai.chat.completions.create(
57+
model="gpt-4",
58+
messages=[
59+
{"role": "user", "content": "What is the capital of France?"},
60+
],
61+
)
62+
print("result: ", result)
63+
```
64+
65+
To learn more about using Gateway, check out the [Gateway documentation](../gateway/index.md). This also includes instructions for self-hosting and alternative LLM providers.
66+
67+
To determine the dataset name, replace `my-first-dataset` in the URL with the name of your dataset.
68+
69+
### Option B: Use the Invariant SDK
70+
71+
If, instead, you want more control over the shape and content of your traces, you can also use the manual upload method via the Invariant SDK.
72+
73+
#### B.1 Install the SDK
3374

34-
Next, install the Invariant SDK in your Python environment, by running the following command. See [Installation](api/sdk-installation.md) for alternative methods using different package managers.
75+
First, install the Invariant SDK in your Python environment, by running the following command. See [Installation](api/sdk-installation.md) for alternative methods using different package managers.
3576

3677
```bash
3778
pip install invariant-sdk
3879
```
3980

4081
> **Self-Host** Note that for the self-hosted version of Explorer, you will need to [configure the SDK](./self-hosted.md/#usage-and-access) to point to your custom endpoint.
4182
42-
## 4. Prepare Your Traces and Upload
83+
#### B.2 Prepare Your Traces and Upload
4384

4485
Now, you can start preparing your AI agent traces for upload. The Invariant SDK then provides a `Client` class that you can use to upload your traces in an Invariant-compatible format:
4586

@@ -82,7 +123,7 @@ To learn more about the expected trace format see the chapter on the [trace form
82123

83124
## Work With Your Traces in Explorer
84125

85-
You can now navigate to the following URL to view your uploaded traces:
126+
After uploading your traces, you can now navigate to the following URL to view your uploaded traces:
86127

87128
```
88129
https://explorer.invariantlabs.ai/<your_username>/my-first-dataset/t/1

0 commit comments

Comments
 (0)