> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zespan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart: instrument your first agent in 5 minutes

> Send your first agent trace to Zespan by wrapping your LLM client or agent framework with the SDK. No manual instrumentation required — two lines of setup.

Zespan instruments your agents and LLM calls by wrapping your existing clients. Once initialized, every agent run, tool call, and model interaction is automatically captured and sent to your project's dashboard. This guide walks through the setup using Node.js and OpenAI, with a Python alternative included.

<Steps>
  <Step title="Create your account and project">
    Go to [app.zespan.com](https://app.zespan.com) and sign up for a free account. After verifying your email, you'll be taken through the onboarding wizard:

    1. **Create an organization** — your billing workspace.
    2. **Create a project** — an isolated container for agent events. Name it after the application you're instrumenting (e.g. `my-support-agent-production`).
    3. **Copy your API key** — shown once after project creation. It starts with `zsp_` followed by 64 hex characters.

    <Warning>
      Your API key is shown in full only once. If you lose it, rotate it from **Settings → API Keys** — the old key remains valid for 24 hours during rollover.
    </Warning>
  </Step>

  <Step title="Install the SDK">
    <Tabs>
      <Tab title="TypeScript / Node.js">
        ```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
        npm install @zespan/sdk openai
        ```
      </Tab>

      <Tab title="Python">
        ```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
        pip install zespan openai
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Initialize and wrap your client">
    Add the following at the entry point of your application — before any agent or LLM calls are made.

    <Tabs>
      <Tab title="TypeScript / Node.js">
        ```typescript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
        import { zespan } from "@zespan/sdk";
        import OpenAI from "openai";

        zespan.init({
          apiKey: process.env.ZESPAN_API_KEY!,
          environment: "production",
        });

        const openai = zespan.wrapOpenAI(new OpenAI());
        ```

        `zespan.init()` initializes the global SDK client. `wrapOpenAI()` patches the OpenAI client so all calls — and every agent step that goes through it — are automatically traced. Your existing code is unchanged.
      </Tab>

      <Tab title="Python">
        ```python theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
        import os

        import zespan

        zespan.init(
            api_key=os.environ["ZESPAN_API_KEY"],
            environment="production",
        )
        zespan.patch_openai()

        import openai  # import after patching
        ```

        `zespan.patch_openai()` monkey-patches both sync and async `openai.chat.completions.create`. Exceptions are always re-raised so your existing error handling is unaffected.
      </Tab>
    </Tabs>

    <Note>
      Set the `ZESPAN_API_KEY` environment variable to the API key from the dashboard. The SDK logs a warning if the key format is invalid.
    </Note>
  </Step>

  <Step title="Run your agent or make an LLM call">
    Use your client exactly as you would normally. The SDK captures everything — model name, input and output tokens, cost, latency, tool calls, streaming TTFT, and finish reason.

    <Tabs>
      <Tab title="TypeScript / Node.js">
        ```typescript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
        import { zespan, withAgent } from "@zespan/sdk";
        import OpenAI from "openai";

        zespan.init({ apiKey: process.env.ZESPAN_API_KEY!, environment: "production" });
        const openai = zespan.wrapOpenAI(new OpenAI());

        // Wrap as an agent to see the full agent trace
        await withAgent(
          {
            name: "SupportAgent",
            role: "specialist",
            tools: [{ name: "lookup_order", description: "Look up an order by ID" }],
          },
          async (agent) => {
            agent.logPlan(["Understand request", "Look up order", "Draft response"]);

            const order = await agent.traceTool(
              "lookup_order",
              { id: "ORD-123" },
              () => Promise.resolve({ status: "delivered", total: 49.99 })
            );

            const response = await openai.chat.completions.create({
              model: "gpt-4o",
              messages: [
                { role: "system", content: "You are a helpful support agent." },
                { role: "user", content: `Order ${order}: help me with my refund.` },
              ],
            });

            console.log(response.choices[0].message.content);
          }
        );
        ```
      </Tab>

      <Tab title="Python">
        ```python theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
        import os

        import zespan
        from zespan import with_agent
        import openai

        zespan.init(api_key=os.environ["ZESPAN_API_KEY"], environment="production")
        zespan.patch_openai()

        client = openai.OpenAI()

        with with_agent(
            name="SupportAgent",
            role="specialist",
            tools=[{"name": "lookup_order", "description": "Look up an order"}],
        ) as agent:
            agent.log_plan(["Understand request", "Look up order", "Draft response"])

            order = agent.trace_tool(
                "lookup_order",
                {"id": "ORD-123"},
                lambda: {"status": "delivered", "total": 49.99},
            )

            response = client.chat.completions.create(
                model="gpt-4o",
                messages=[
                    {"role": "system", "content": "You are a helpful support agent."},
                    {"role": "user", "content": f"Order {order}: help with refund."},
                ],
            )
            print(response.choices[0].message.content)
        ```
      </Tab>

      <Tab title="Just an LLM call">
        If you're not using agents yet, a bare LLM call is traced automatically:

        ```typescript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
        const response = await openai.chat.completions.create({
          model: "gpt-4o",
          messages: [{ role: "user", content: "Explain agent observability." }],
        });
        ```

        You'll still see the full span: model, tokens, cost, latency, and finish reason.
      </Tab>
    </Tabs>
  </Step>

  <Step title="View your trace in the dashboard">
    Open [app.zespan.com](https://app.zespan.com) and navigate to your project. Within a few seconds you should see your trace in the **Traces** view. Click any row to open the flame graph — each bar is a span (agent scope, tool call, LLM call) with full cost and latency breakdown.

    <Tip>
      If no trace appears after 15 seconds, check that your API key is correct and that your process did not exit before the SDK flushed. Call `await zespan.getClient().flush()` (TypeScript) or `zespan.flush()` (Python) at the end of your script to force an immediate flush. See the [Serverless guide](/guides/serverless) if running in Lambda or Vercel.
    </Tip>
  </Step>
</Steps>

## SDK initialization options

<Tabs>
  <Tab title="TypeScript">
    | Option          | Type       | Default                  | Description                                                                                             |
    | --------------- | ---------- | ------------------------ | ------------------------------------------------------------------------------------------------------- |
    | `apiKey`        | `string`   | **Required**             | Your project API key. Must start with `zsp_`.                                                           |
    | `environment`   | `string`   | `"production"`           | Tags every event with an environment label.                                                             |
    | `storePrompts`  | `boolean`  | `true`                   | Store prompt and completion text. PII redaction applied before transmission. Set to `false` to disable. |
    | `sampleRate`    | `number`   | `1.0`                    | Fraction of calls to trace (0.0–1.0).                                                                   |
    | `redactKeys`    | `string[]` | Common PII keys          | Tag/metadata keys whose values are redacted before sending.                                             |
    | `debug`         | `boolean`  | `false`                  | Log SDK activity to the console.                                                                        |
    | `batchSize`     | `number`   | `50`                     | Events to collect before flushing.                                                                      |
    | `flushInterval` | `number`   | `2000`                   | Milliseconds between automatic flushes.                                                                 |
    | `baseURL`       | `string`   | `https://api.zespan.com` | Override for self-hosted deployments.                                                                   |
  </Tab>

  <Tab title="Python">
    | Option           | Type        | Default                  | Description                                                                                             |
    | ---------------- | ----------- | ------------------------ | ------------------------------------------------------------------------------------------------------- |
    | `api_key`        | `str`       | **Required**             | Your project API key.                                                                                   |
    | `environment`    | `str`       | `"production"`           | Environment label.                                                                                      |
    | `store_prompts`  | `bool`      | `True`                   | Store prompt and completion text. PII redaction applied before transmission. Set to `False` to disable. |
    | `sample_rate`    | `float`     | `1.0`                    | Fraction of calls to trace.                                                                             |
    | `redact_keys`    | `list[str]` | Common PII keys          | Keys to redact from tags/metadata.                                                                      |
    | `debug`          | `bool`      | `False`                  | Log flush activity to stdout.                                                                           |
    | `batch_size`     | `int`       | `50`                     | Events per flush.                                                                                       |
    | `flush_interval` | `float`     | `2.0`                    | Seconds between automatic flushes.                                                                      |
    | `base_url`       | `str`       | `https://api.zespan.com` | Override for self-hosted deployments.                                                                   |
  </Tab>
</Tabs>

## Tracing other frameworks

<CardGroup cols={2}>
  <Card title="Anthropic" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/claude.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=cb0f043b399d34635dc564583c1c53e7" href="/sdk/integrations/anthropic" width="16" height="16" data-path="logos/claude.svg">
    `zespan.wrapAnthropic(new Anthropic())`
  </Card>

  <Card title="Google Gemini" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/gemini.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=afee856e9774ce9d180b04fa0b8056a0" href="/sdk/integrations/google-genai" width="16" height="16" data-path="logos/gemini.svg">
    `zespan.wrapGoogle(new GoogleGenerativeAI(key))`
  </Card>

  <Card title="AWS Bedrock" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/bedrock.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=2f4f077d0718a57549a7fc4af516148f" href="/sdk/integrations/bedrock" width="16" height="16" data-path="logos/bedrock.svg">
    `zespan.wrapBedrock(new BedrockRuntimeClient())`
  </Card>

  <Card title="Mistral" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/mistral.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=44eef65716e18d95a486a6f7b0c86028" href="/sdk/integrations/mistral" width="16" height="16" data-path="logos/mistral.svg">
    `zespan.wrapMistral(new Mistral())`
  </Card>

  <Card title="Groq" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/groq.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=f6fcfdb3cd832c9837ce6ccfeda435a6" href="/sdk/integrations/groq" width="16" height="16" data-path="logos/groq.svg">
    `zespan.wrapGroq(new Groq())`
  </Card>

  <Card title="OpenRouter" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/openrouter.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=277236916df80aa1dc6aa9066af56126" href="/sdk/integrations/openrouter" width="16" height="16" data-path="logos/openrouter.svg">
    `zespan.wrapOpenAI(new OpenAI({ baseURL: "..." }))`
  </Card>

  <Card title="LiteLLM" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/litellm.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=4205b8e9f285701f19d7189bf6407b4d" href="/sdk/integrations/litellm" width="24" height="24" data-path="logos/litellm.svg">
    Drop-in proxy — point your SDK at the LiteLLM base URL.
  </Card>

  <Card title="LangChain" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/langchain.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=c3bbfb54e280e12ac72809c31d88cab7" href="/sdk/integrations/langchain" width="16" height="16" data-path="logos/langchain.svg">
    Full chain, agent executor, and retriever tracing via callback handler.
  </Card>

  <Card title="Google ADK" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/google-adk.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=c5b8104c65f437edcec1412ccd47069a" href="/sdk/integrations/google-adk" width="16" height="16" data-path="logos/google-adk.svg">
    Multi-agent tracing with `instrumentADK`, `wrapADKRunner`, or `wrapADKAgent`.
  </Card>

  <Card title="CrewAI" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/crewai.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=2da96512448ba9e2688c28c1d01283a7" href="/sdk/integrations/crewai" width="16" height="16" data-path="logos/crewai.svg">
    Crew and task tracing via the Zespan CrewAI integration.
  </Card>

  <Card title="AutoGen" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/autogen.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=e309e035e88d2a232e2d612019dc4212" href="/sdk/integrations/autogen" width="96" height="85" data-path="logos/autogen.svg">
    Multi-agent conversation and tool tracing for AutoGen / AG2.
  </Card>

  <Card title="LlamaIndex" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/llamaindex.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=522df86f3e6759e63829c8f3d403481e" href="/sdk/integrations/llamaindex" width="16" height="16" data-path="logos/llamaindex.svg">
    Query engine, retriever, and agent tracing via callback handler.
  </Card>

  <Card title="Vercel AI SDK" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/vercel.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=7b3d2a61b7e83b7611afdb890886002e" href="/sdk/integrations/vercel-ai" width="24" height="24" data-path="logos/vercel.svg">
    `generateText`, `streamText`, and `generateObject` traced automatically.
  </Card>

  <Card title="Haystack" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/haystack.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=c8cac150fddc9229bac6bf70794d7d92" href="/sdk/integrations/haystack" width="24" height="24" data-path="logos/haystack.svg">
    Pipeline component and retriever tracing for Haystack 2.x.
  </Card>

  <Card title="Semantic Kernel" icon="https://mintcdn.com/zespancom/OVq7q4R1vLkWzInd/logos/microsoft.svg?fit=max&auto=format&n=OVq7q4R1vLkWzInd&q=85&s=9524fa9ca09151c8c97357f69342cb74" href="/sdk/integrations/semantic-kernel" width="16" height="16" data-path="logos/microsoft.svg">
    Kernel function and planner tracing for Microsoft Semantic Kernel.
  </Card>
</CardGroup>
