- The LangSmith SDK (
@traceable) for application-level tracing. - LiteLLM’s built-in langsmith callback for model-level logging.
- The LiteLLM Proxy for gateway-level tracing.
Installation
Install the following when using either the LiteLLM Python SDK or LiteLLM Proxy:Use the LiteLLM Python SDK
LiteLLM supports two ways to send traces to LangSmith, which operate at different layers:- LangSmith SDK tracing with
LANGSMITH_TRACING=trueenables application-level tracing via the LangSmith SDK. This is useful when you want to trace broader business logic, multi-step pipelines, or spans created with@traceable. - LiteLLM’s built-in
langsmithcallback logs model calls directly from LiteLLM. This is recommended when you want to trace LiteLLM requests specifically, or run async applications.
Avoid enabling LiteLLM’s
langsmith callback and LangSmith tracing for the same LiteLLM calls, as this can result in duplicate traces.Use LANGSMITH_TRACING and traceable
You can use LANGSMITH_TRACING=true together with @traceable for predictable traces in LangSmith. This approach ensures that the Input and Output columns reflect your function arguments and return values, allowing you to preserve the full message structure (including role and content). It also works reliably in simple synchronous scripts, without requiring an asyncio event loop or additional callback configuration.
-
Set the following environment variables to enable LangSmith tracing for LiteLLM Python SDK usage:
Create LangSmith API keys in the LangSmith UI. Depending on what provider you’re using, you’ll also need to set API keys:
-
Add the following code to your script file:
@traceableinstruments your function as a LangSmith run. WhenLANGSMITH_TRACING=trueis set, LangSmith automatically:- Creates a run when the function is invoked.
- Records the function arguments as the run inputs.
- Executes the function body (including the LiteLLM call).
- Records the function’s return value as the run output.
- Captures timing, errors, and nested spans (if any).
messagesargument becomes the trace input, and the returned assistant message object becomes the trace output. The LiteLLM call itself runs normally—@traceablewraps it with observability rather than modifying its behavior. This approach traces your application logic, not just the model call.
Log LiteLLM call with the langsmith callback
LiteLLM can send traces directly to LangSmith using its built-in callback system. This is useful when running LiteLLM inside an async Python service and you want LiteLLM itself to emit model-level logs.
LiteLLM callbacks run in an asynchronous environment. When making asynchronous calls with litellm.acompletion(), you can enable the langsmith callback to log successful model calls.
-
Set the following environment variables:
Create LangSmith API keys in the LangSmith UI. Depending on what provider you’re using, you’ll also need to set API keys:
-
To run this in a minimal script:
- Use
acompletion()(async API). - Run with
asyncio.run(...)to create an event loop. - Set
langsmith_batch_size = 1to flush immediately.
The callback sends LiteLLM’s model request and response data directly to LangSmith, including provider metadata and token usage. Because LiteLLM controls the payload, the Input and Output columns may include additional metadata compared to the@traceableexample. - Use
Use the LiteLLM Proxy
The LiteLLM proxy runs as a standalone server and exposes an OpenAI-compatible API.-
To have the proxy log requests directly to LangSmith, configure the callback in
config.yaml: -
Set environment variables in your proxy environment:
The LiteLLM proxy runs as a separate service. If you enable LangSmith tracing at the proxy level, you must configure
LANGSMITH_API_KEYand related environment variables in the proxy’s runtime environment. These settings are not shared with your application process. -
Start the proxy:
By default, the proxy runs at
http://localhost:4000/v1. Your application calls it using any OpenAI-compatible client (Python, JavaScript, curl, etc.). Withcallbacks: ["langsmith"]enabled, the proxy sends model request and response data directly to LangSmith. No tracing configuration is required in the client application. -
Call the proxy from another terminal window:
The client sends a normal chat completion request, and the proxy handles provider routing and response formatting.
Next steps
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

