Lens API reference
Lens runs as its own service next to the gateway. You never call it directly. You call the gateway under /lens/... with your normal gateway key or Admin UI session, and the gateway forwards the request to Lens with a short-lived identity token for you, so Lens applies its own team and role rules. That is why the published API reference shows the Lens routes as one forwarding route, /lens/{path}, and this page lists what lives behind it.
A real-world scenario
A support lead wants a nightly script that lists the investigations their team opened that day and exports the failing cases into a dataset for an eval. The script uses the team's gateway key, calls GET /lens to list investigations and POST /lens/datasets to save the cases, and never needs a Lens credential of its own.
How to call a Lens route
-
Make sure Lens is connected. In the Admin UI open Lens. When the setup card is gone, Lens is reachable. Over the API,
GET /lens/serviceanswers with the connection status. -
Send the request to the gateway with the path from the table below:
curl "http://localhost:4000/lens/datasets" \-H "Authorization: Bearer $SPANWAY_API_KEY" -
Read the answer. Lens answers in JSON. The errors the gateway itself can return are listed under Errors, anything else is Lens's own answer.
Only content-type, x-lens-contract and idempotency-key travel to Lens from your request headers. The body and query string travel unchanged. Routes under /lens/evals and /lens/datasets need a license with the evals feature. Every successful change (POST, PUT, PATCH or DELETE, except the read-only searches) writes a gateway audit row naming you, the method and the Lens path, never the body.
Routes
Most read routes are open to proxy admins and admin viewers and to team members for their own team's objects. Changes need a role that may change that kind of object. Lens answers 403 when your role does not cover the route.
Investigations
| Method | Path | What it does |
|---|---|---|
| GET | /lens | Lists the investigations you may see. |
| POST | /lens | Starts a new investigation from a question and a selection of runs. |
| POST | /lens/watch-all | Starts watching every agent at once, so new runs are checked as they arrive. |
| GET | /lens/{lens_id} | Reads one investigation. |
| PUT | /lens/{lens_id} | Changes an investigation, for example its title or schedule. |
| POST | /lens/{lens_id}/cancel | Stops an investigation that is running. |
| GET | /lens/{lens_id}/runs | Lists the runs of an investigation. |
| POST | /lens/{lens_id}/runs | Runs the investigation again now. |
| GET | /lens/{lens_id}/runs/{job_id} | Reads one run of an investigation with its findings. |
| GET | /lens/{lens_id}/runs/{job_id}/reviews | Lists the reviews left on a run. |
| GET | /lens/{lens_id}/executions/{execution_id} | Reads the recorded steps of one agent run that an investigation looked at. |
| POST | /lens/{lens_id}/findings/import | Imports findings from another tool into an investigation, up to 64 KB per request. |
| PATCH | /lens/{lens_id}/findings/{finding_id} | Records your verdict on a finding, for example that it is a real problem or a false alarm. |
Activity and signals
| Method | Path | What it does |
|---|---|---|
| GET | /lens/activity/available | Says which kinds of recorded activity, traces or request logs, Lens can read. Proxy admins and admin viewers only. |
| GET | /lens/agents | Lists the agent names seen in recorded activity. Proxy admins and admin viewers only. |
| POST | /lens/preview/sample | Shows a sample of the runs a selection would cover, before you start an investigation. |
| POST | /lens/traces/findings | Counts the findings already raised for a list of traces. Proxy admins and admin viewers only. |
| GET | /lens/signals | Reads the signals Lens watches for, such as errors or slow answers. |
| PUT | /lens/signals | Saves the signals Lens watches for. |
| POST | /lens/traces/signals | Checks a list of traces against the saved signals. |
Datasets
| Method | Path | What it does |
|---|---|---|
| GET | /lens/datasets | Lists datasets. |
| POST | /lens/datasets | Creates a dataset. |
| POST | /lens/datasets/build | Builds a dataset from recorded runs. |
| GET | /lens/datasets/resolve | Finds a dataset revision by name, for an eval run. |
| GET | /lens/datasets/{dataset_id} | Reads one dataset. |
| GET | /lens/datasets/{dataset_id}/export | Downloads a dataset. |
| POST | /lens/datasets/{dataset_id}/revisions | Saves a new revision of a dataset. |
| GET | /lens/datasets/{dataset_id}/revisions/{revision}/cases | Lists the cases of one dataset revision. |
Evals
| Method | Path | What it does |
|---|---|---|
| GET | /lens/evals | Lists eval definitions. |
| GET | /lens/evals/{name} | Reads one eval definition. |
| PUT | /lens/evals/{name} | Saves an eval definition. |
| GET | /lens/evals/runs | Lists eval runs. |
| POST | /lens/evals/runs | Starts an eval run. |
| GET | /lens/evals/runs/{run} | Reads one eval run with its scores. |
| GET | /lens/evals/runs/{run}/cases | Lists the cases of an eval run. |
| GET | /lens/evals/runs/{run}/cases/{case_id} | Reads one case of an eval run. |
| PUT | /lens/evals/runs/{run}/results/{case_id}/{trial} | Records the result of one trial of one case. |
| POST | /lens/evals/runs/{run}/finish | Marks an eval run as finished. |
Feedback
| Method | Path | What it does |
|---|---|---|
| GET | /lens/feedback | Reads your feedback on a run. |
| PUT | /lens/feedback | Saves feedback on a run, such as a thumbs up or a comment. |
| DELETE | /lens/feedback | Removes your feedback on a run. |
| POST | /lens/feedback/summary | Summarises the feedback left on a list of runs. |
Tracing keys
| Method | Path | What it does |
|---|---|---|
| GET | /lens/tracing/keys | Lists the keys your services use to send traces to Lens. |
| POST | /lens/tracing/keys | Creates a tracing key. The secret is shown once in the answer. |
| DELETE | /lens/tracing/keys/{key_id} | Revokes a tracing key, so traces sent with it are refused. |
Models and the gateway connection
| Method | Path | What it does |
|---|---|---|
| GET | /lens/service | Reads the connection between Lens and the gateway. |
| GET | /lens/gateway | Reads which gateway Lens uses to call models. |
| POST | /lens/gateway/refresh | Reloads the model list from the gateway. |
| GET | /lens/models | Lists the models Lens may use. |
| GET | /lens/model_group/info | Lists the model groups Lens may use, with their details. |
Code host connections
| Method | Path | What it does |
|---|---|---|
| GET | /lens/github/status | Says whether a code host app is connected. |
| POST | /lens/github/authorize | Starts connecting your code host account. |
| GET | /lens/github/authorizations/{id} | Reads the state of a connection attempt. |
| GET | /lens/github/callback | Where the code host sends you back after you approve the connection. |
| GET | /lens/github/setup | Where the code host sends you back after installing the app. |
| PUT | /lens/github/connections/{agent} | Links an agent to a repository. |
| DELETE | /lens/github/connections/{agent} | Unlinks an agent from its repository. |
| POST | /lens/github/report | Posts an investigation report to a pull request. |
| POST | /lens/github/rerun | Runs the checks for a pull request again. |
| POST | /lens/github/service/authorize | Starts connecting a service account instead of a person. |
| GET | /lens/github/service/connect/{id} | Shows the consent screen for a service connection. |
| POST | /lens/github/service/connect/{id} | Gives consent for a service connection. |
| POST | /lens/github/service/redeem | Exchanges a one-time code for a service connection. |
| GET | /lens/github/service/connections/{id} | Reads a service connection. |
| DELETE | /lens/github/service/connections/{id} | Removes a service connection. |
| POST | /lens/github/service/connections/{id}/report | Posts a report through a service connection. |
| POST | /lens/github/service/connections/{id}/rerun | Runs the checks again through a service connection. |
Errors
These are the gateway's own answers. Any other status comes from Lens itself and is passed through unchanged.
| Status | Message | Cause | Fix |
|---|---|---|---|
| 401 | Authentication Error, No api key passed in. | The gateway got no key or session. | Send Authorization: Bearer <key>. |
| 400 | Invalid Lens path | The path climbs out of the Lens API, for example with ... | Use a path from the tables above. |
| 403 | Lens requires an authenticated user or key | The caller has no user or key identity. | Use a key that belongs to a user or team. |
| 403 | The evals license message | A route under /lens/evals or /lens/datasets on a license without the evals feature. | Add the feature to the license. |
| 409 | contract_version | The request sent more than one x-lens-contract header. | Send the header once. |
| 413 | Lens request is too large | The request or Lens's answer is larger than 64 MiB. | Send less, or page through the data. |
| 503 | Configure SPANWAY_LENS_URL and LENS_GATEWAY_SECRET for the Lens service | Lens is not configured on this gateway. | Follow the setup card on the Lens page. |
| 503 | Set SPANWAY_LENS_SERVICE_TOKEN to the same secret of at least 32 characters on Spanway and Lens | The shared secret is missing or too short. | Set the same secret on both sides and restart. |
| 503 | Lens forwarding capacity is busy; retry shortly | Too many Lens requests are in flight. | Retry after the Retry-After seconds. |
| 503 | Lens service is unavailable | Lens did not answer. | Check that the Lens service is running and reachable from the gateway. |
A 403 or 404 that is not in this table comes from Lens's own role rules or means the object does not exist.
Logs
The gateway writes no log line of its own for a forwarded request that succeeds. A failed forward appears with the other Lens lines in the log reference.
Related
- Lens overview.
- Search, sessions, agent graph and comments.
- Audit logs, where forwarded Lens changes are recorded.