Skip to main content

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​

  1. 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/service answers with the connection status.

  2. 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"
  3. 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​

MethodPathWhat it does
GET/lensLists the investigations you may see.
POST/lensStarts a new investigation from a question and a selection of runs.
POST/lens/watch-allStarts 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}/cancelStops an investigation that is running.
GET/lens/{lens_id}/runsLists the runs of an investigation.
POST/lens/{lens_id}/runsRuns 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}/reviewsLists 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/importImports 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​

MethodPathWhat it does
GET/lens/activity/availableSays which kinds of recorded activity, traces or request logs, Lens can read. Proxy admins and admin viewers only.
GET/lens/agentsLists the agent names seen in recorded activity. Proxy admins and admin viewers only.
POST/lens/preview/sampleShows a sample of the runs a selection would cover, before you start an investigation.
POST/lens/traces/findingsCounts the findings already raised for a list of traces. Proxy admins and admin viewers only.
GET/lens/signalsReads the signals Lens watches for, such as errors or slow answers.
PUT/lens/signalsSaves the signals Lens watches for.
POST/lens/traces/signalsChecks a list of traces against the saved signals.

Datasets​

MethodPathWhat it does
GET/lens/datasetsLists datasets.
POST/lens/datasetsCreates a dataset.
POST/lens/datasets/buildBuilds a dataset from recorded runs.
GET/lens/datasets/resolveFinds a dataset revision by name, for an eval run.
GET/lens/datasets/{dataset_id}Reads one dataset.
GET/lens/datasets/{dataset_id}/exportDownloads a dataset.
POST/lens/datasets/{dataset_id}/revisionsSaves a new revision of a dataset.
GET/lens/datasets/{dataset_id}/revisions/{revision}/casesLists the cases of one dataset revision.

Evals​

MethodPathWhat it does
GET/lens/evalsLists eval definitions.
GET/lens/evals/{name}Reads one eval definition.
PUT/lens/evals/{name}Saves an eval definition.
GET/lens/evals/runsLists eval runs.
POST/lens/evals/runsStarts an eval run.
GET/lens/evals/runs/{run}Reads one eval run with its scores.
GET/lens/evals/runs/{run}/casesLists 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}/finishMarks an eval run as finished.

Feedback​

MethodPathWhat it does
GET/lens/feedbackReads your feedback on a run.
PUT/lens/feedbackSaves feedback on a run, such as a thumbs up or a comment.
DELETE/lens/feedbackRemoves your feedback on a run.
POST/lens/feedback/summarySummarises the feedback left on a list of runs.

Tracing keys​

MethodPathWhat it does
GET/lens/tracing/keysLists the keys your services use to send traces to Lens.
POST/lens/tracing/keysCreates 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​

MethodPathWhat it does
GET/lens/serviceReads the connection between Lens and the gateway.
GET/lens/gatewayReads which gateway Lens uses to call models.
POST/lens/gateway/refreshReloads the model list from the gateway.
GET/lens/modelsLists the models Lens may use.
GET/lens/model_group/infoLists the model groups Lens may use, with their details.

Code host connections​

MethodPathWhat it does
GET/lens/github/statusSays whether a code host app is connected.
POST/lens/github/authorizeStarts connecting your code host account.
GET/lens/github/authorizations/{id}Reads the state of a connection attempt.
GET/lens/github/callbackWhere the code host sends you back after you approve the connection.
GET/lens/github/setupWhere 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/reportPosts an investigation report to a pull request.
POST/lens/github/rerunRuns the checks for a pull request again.
POST/lens/github/service/authorizeStarts 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/redeemExchanges 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}/reportPosts a report through a service connection.
POST/lens/github/service/connections/{id}/rerunRuns 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.

StatusMessageCauseFix
401Authentication Error, No api key passed in.The gateway got no key or session.Send Authorization: Bearer <key>.
400Invalid Lens pathThe path climbs out of the Lens API, for example with ...Use a path from the tables above.
403Lens requires an authenticated user or keyThe caller has no user or key identity.Use a key that belongs to a user or team.
403The evals license messageA route under /lens/evals or /lens/datasets on a license without the evals feature.Add the feature to the license.
409contract_versionThe request sent more than one x-lens-contract header.Send the header once.
413Lens request is too largeThe request or Lens's answer is larger than 64 MiB.Send less, or page through the data.
503Configure SPANWAY_LENS_URL and LENS_GATEWAY_SECRET for the Lens serviceLens is not configured on this gateway.Follow the setup card on the Lens page.
503Set SPANWAY_LENS_SERVICE_TOKEN to the same secret of at least 32 characters on Spanway and LensThe shared secret is missing or too short.Set the same secret on both sides and restart.
503Lens forwarding capacity is busy; retry shortlyToo many Lens requests are in flight.Retry after the Retry-After seconds.
503Lens service is unavailableLens 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.