---
title: "Direct LLM SDKs"
description: "Auto-trace tool calls from raw LLM SDK responses — wrap once, trace everything"
---

`wrap_llm()` wraps LLM SDK clients directly. Every LLM generation call and tool use block in the response is automatically traced — no callback wiring needed.

## When to use this

| Scenario | Use |
|----------|-----|
| Agent built with LangChain/LangGraph | [LangChain callback](/sdk/integrations/langchain) |
| Agent using raw OpenAI/Anthropic/Gemini SDK | **`wrap_llm()` — see pages below** |
| Agent using MCP sessions directly | [`wrap()`](/sdk/python) |

## Supported SDKs

<CardGroup cols={3}>
  <Card title="Gemini SDK" icon="bolt" href="/sdk/integrations/gemini-sdk">
    `google.genai.Client` — new SDK with function calling
  </Card>
  <Card title="OpenAI SDK" icon="robot" href="/sdk/integrations/openai-sdk">
    `openai.OpenAI` / `AsyncOpenAI` — chat completions + tools
  </Card>
  <Card title="Anthropic SDK" icon="message" href="/sdk/integrations/anthropic-sdk">
    `anthropic.Anthropic` / `AsyncAnthropic` — messages + tool_use
  </Card>
</CardGroup>

## How it works

```python
import langsight

ls = langsight.init()  # reads LANGSIGHT_URL from env
client = ls.wrap_llm(your_llm_client, agent_name="my-agent", session_id="sess-001")
# Use client exactly as before — all calls auto-traced
```

`wrap_llm()` auto-detects the SDK based on the client class:

| Class | Detected SDK |
|-------|-------------|
| `openai.OpenAI`, `openai.AsyncOpenAI` | OpenAI |
| `anthropic.Anthropic`, `anthropic.AsyncAnthropic` | Anthropic |
| `google.genai.Client` | Gemini (new SDK) |
| `google.generativeai.GenerativeModel` | Gemini (legacy) |
| Anything else | Returned unchanged (fail-open) |

## What gets traced

For each generation call, LangSight emits:

1. **LLM generation span** — model, tokens, latency, `span_type="agent"`
2. **Tool call spans** (one per tool use) — tool name, arguments, `parent_span_id` linking to the LLM span

## Combining with MCP tracing

`wrap_llm()` and `wrap()` work independently. Use both when your agent calls LLM APIs directly and also uses MCP servers:

```python
client = ls.wrap_llm(genai.Client(), agent_name="my-agent", session_id=sid)
traced_mcp = ls.wrap(mcp_session, server_name="postgres-mcp", session_id=sid)
```

Both share the same `session_id`, so all spans appear in a single session trace.

## PII redaction

```python
ls = LangSightClient(url="http://localhost:8000", redact_payloads=True)
# Tool arguments from LLM responses are not captured
```
