Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.langchain.com/llms.txt

Use this file to discover all available pages before exploring further.

Many LLM providers accept requests in the same format as the OpenAI API. To trace calls from these providers to LangSmith, construct an OpenAI client pointed at the provider’s base URL, then wrap it with wrap_openai / wrapOpenAI. Use wrap_openai / wrapOpenAI for direct API calls. Use @traceable when you need to trace application logic around the call or set metadata per invocation.
wrap_openai / wrapOpenAI@traceable / traceable
Token trackingAutomaticRequires run_type="llm"
Run typeLLM (set automatically)Chain by default
TracesThe API callThe function wrapping it
MetadataClient-level only (Python); client-level or per-call (TypeScript)Per-call via langsmith_extra
To trace OpenAI directly, refer to Trace OpenAI applications.

Setup

pip install langsmith openai
export LANGSMITH_API_KEY=<your-api-key>
export LANGSMITH_TRACING=true

Trace API calls

import os

import openai
from langsmith import wrappers

client = wrappers.wrap_openai(
    openai.OpenAI(
        base_url="https://<provider-base-url>/v1",
        api_key=os.environ["PROVIDER_API_KEY"],
    )
)

completion = client.chat.completions.create(
    model="<provider-model-name>",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(completion.choices[0].message.content)

Add metadata

Pass tracing_extra when wrapping the client. The metadata applies to all calls made with that client.
import os

import openai

from langsmith import wrappers

client = wrappers.wrap_openai(
    openai.OpenAI(
        base_url="https://<provider-base-url>/v1",
        api_key=os.environ["PROVIDER_API_KEY"],
    ),
    tracing_extra={"metadata": {"environment": "production"}},
)
Some providers have dedicated setup guides that use @traceable or a native callback. These approaches trace at the function level rather than wrapping the client directly, or integrate with the provider’s own SDK and routing layer.
  • DeepSeek: OpenAI-compatible API; guide uses @traceable with custom provider metadata
  • LiteLLM: proxy that exposes an OpenAI-compatible endpoint; guide covers @traceable and LiteLLM’s built-in LangSmith callback