Skip to main content

LangSmith integration

LangSmith is a tracing and evaluation platform. With this integration each request through the gateway becomes a LangSmith run with inputs, outputs, token usage, cost and metadata, so teams that already trace their applications in LangSmith see gateway traffic next to their own runs.

A real-world scenario​

A team traces its agent in LangSmith and wants the model calls the agent makes through the gateway to appear inside the same traces. The application passes its LangSmith run id as parent_run_id in the request metadata. Each model call then shows up in LangSmith as a child run of the agent's trace, with the model, tokens and cost the gateway recorded.

Turn it on from the Admin UI​

  1. Sign in as a proxy admin and open Settings, then Logging & Alerts. Click Add Callback.
  2. Pick Langsmith in the Callback dropdown and fill in the API key, the project and, for a self-hosted deployment, the base URL. The sampling rate takes a value from 0 to 1.
  3. Click Add Callback. The table shows a langsmith row with the badge Success.

Turn it on in the config file​

spanway_settings:
success_callback: ["langsmith"]
failure_callback: ["langsmith"]
VariablePurpose
LANGSMITH_API_KEYAPI key.
LANGSMITH_PROJECTProject runs are written to.
LANGSMITH_BASE_URLLangSmith URL, for self-hosted deployments.
LANGSMITH_DEFAULT_RUN_NAMERun name when the request does not set one.
LANGSMITH_BATCH_SIZENumber of runs sent per batch.
LANGSMITH_SAMPLING_RATEFraction of requests to log, between 0 and 1.
LANGSMITH_TENANT_IDTenant for multi-tenant deployments.

Runs are batched and sent asynchronously, so logging does not add latency to requests.

Set LangSmith fields​

Request metadata controls how a run appears in LangSmith.

curl -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "Classify this email"}],
"metadata": {
"run_name": "email-classifier",
"project_name": "support-automation",
"run_id": "0b1f2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d",
"parent_run_id": "9e0f1a2b-3c4d-4e5f-8a6b-0b1f2c3d4e5f",
"tags": ["classifier", "v3"],
"trace_id": "ticket-4411"
}
}'

Expected result: once the batch is sent, the support-automation project shows a run named email-classifier with your run_id, nested under the parent run, tagged classifier and v3, with the gateway's key alias, team and user in its metadata.

Metadata keyEffect
run_nameName of the run.
project_nameProject for this run, overriding LANGSMITH_PROJECT.
run_idUse your own run id, which lets you add feedback later.
parent_run_idNest the run under one of your own traces.
tagsTags on the run.
trace_idGroups runs into one trace.

Per-team projects​

Attach langsmith_api_key, langsmith_project and langsmith_base_url to a team with a team callback so its keys log to the team's own project, as described in team logging. The key alias, team and user from the gateway are included in run metadata, and turn_off_message_logging removes inputs and outputs from runs.

Errors​

StatusWhereMeaningFix
Runs missing from LangSmithLangSmith projectThe batch has not been sent yet, the sampling rate dropped the request, or the API key cannot write to the project.Wait for a batch, check LANGSMITH_SAMPLING_RATE, and look for Langsmith Error in the gateway log.
400 naming the base URL and the API keySaving the callback in the Admin UIThe base URL changed while the stored key was kept.Retype the API key with the new URL.
403 naming scoped_integrationsTeam callbackPer team projects need the license feature.Use the gateway wide callback, or add the feature.

Logs​

LevelLineMeaning
ERRORLangsmith Error: <status> - <text>LangSmith refused a batch. 401 means the key is wrong, 404 usually means the project or tenant does not exist.
WARNINGA LangSmith line about a run that could not be queuedA single run was dropped, for example because the batch was full. Normal if rare.