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
- Sign in as a proxy admin and open Settings, then Logging & Alerts. Click Add Callback.
- 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.
- Click Add Callback. The table shows a
langsmithrow with the badge Success.
Turn it on in the config file
spanway_settings:
success_callback: ["langsmith"]
failure_callback: ["langsmith"]
| Variable | Purpose |
|---|---|
LANGSMITH_API_KEY | API key. |
LANGSMITH_PROJECT | Project runs are written to. |
LANGSMITH_BASE_URL | LangSmith URL, for self-hosted deployments. |
LANGSMITH_DEFAULT_RUN_NAME | Run name when the request does not set one. |
LANGSMITH_BATCH_SIZE | Number of runs sent per batch. |
LANGSMITH_SAMPLING_RATE | Fraction of requests to log, between 0 and 1. |
LANGSMITH_TENANT_ID | Tenant 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 key | Effect |
|---|---|
run_name | Name of the run. |
project_name | Project for this run, overriding LANGSMITH_PROJECT. |
run_id | Use your own run id, which lets you add feedback later. |
parent_run_id | Nest the run under one of your own traces. |
tags | Tags on the run. |
trace_id | Groups 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
| Status | Where | Meaning | Fix |
|---|---|---|---|
| Runs missing from LangSmith | LangSmith project | The 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 key | Saving the callback in the Admin UI | The base URL changed while the stored key was kept. | Retype the API key with the new URL. |
403 naming scoped_integrations | Team callback | Per team projects need the license feature. | Use the gateway wide callback, or add the feature. |
Logs
| Level | Line | Meaning |
|---|---|---|
| ERROR | Langsmith Error: <status> - <text> | LangSmith refused a batch. 401 means the key is wrong, 404 usually means the project or tenant does not exist. |
| WARNING | A LangSmith line about a run that could not be queued | A single run was dropped, for example because the batch was full. Normal if rare. |
Related
- Logging for every destination.
- Team logging for per team projects.
- Langfuse integration for a similar platform.
- Error reference and log reference.