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

# Quickstart

> Start a session, wrap OpenAI, track a tool call, and flush exported events.

# Quickstart

This example creates a Captar runtime, starts a session with budget and policy,
wraps an OpenAI client, tracks a tool call, and closes the session cleanly.

Use it as the first end-to-end check that your integration is wired correctly.
If this works, the rest of the docs should feel familiar rather than abstract.

```ts theme={null}
import OpenAI from "openai";
import { createCaptar } from "@captar/sdk";

const captar = createCaptar({
  project: "support-bot",
  exporter: { url: process.env.CAPTAR_INGEST_URL! },
});

const session = await captar.startSession({
  budget: {
    maxSpendUsd: 2,
    finalizationReserveUsd: 0.2,
  },
  metadata: {
    _user: "u_123",
    _team: "support",
    feature: "chat",
  },
  policy: {
    call: {
      allowedModels: ["gpt-4.1-mini"],
      maxEstimatedCostUsd: 0.6,
    },
    tool: {
      requireApprovalFor: ["zendesk.createComment"],
    },
  },
});

const openai = captar.wrapOpenAI(
  new OpenAI({ apiKey: process.env.OPENAI_API_KEY }),
  { session },
);

const response = await openai.responses.create({
  model: "gpt-4.1-mini",
  input: "Help me answer this support ticket.",
  max_output_tokens: 200,
});

await captar.trackTool("zendesk.createComment", {
  session,
  estimate: 0.02,
}).run(async () => {
  return { ok: true };
});

await session.close();
await captar.flush();
```

## What this shows

<Steps>
  <Step>Captar estimates request cost before the provider call runs.</Step>
  <Step>Budget is reserved locally so the session cannot overspend silently.</Step>
  <Step>Model and tool policy are evaluated before execution proceeds.</Step>
  <Step>Provider usage is reconciled after the response returns.</Step>
  <Step>Trace, spend, and guardrail events are emitted for platform export.</Step>
</Steps>

## Things to notice

* `createCaptar()` is the project root, not a global singleton.
* `startSession()` is where request-scoped budget and policy live.
* `wrapOpenAI()` keeps the provider client you already know.
* `trackTool()` should wrap external actions that matter to the trace.
* `flush()` matters for jobs, scripts, and short-lived serverless requests.

## Common adjustments

<Tabs items={["Tighter budget", "Different tool rule", "No exporter yet"]}>
  <Tab>
    ```ts theme={null}
    const session = await captar.startSession({
      budget: {
        maxSpendUsd: 0.75,
        finalizationReserveUsd: 0.1,
      },
    });
    ```
  </Tab>

  <Tab>
    ```ts theme={null}
    policy: {
      tool: {
        requireApprovalFor: ["billing.issueRefund"],
      },
    }
    ```
  </Tab>

  <Tab>
    ```ts theme={null}
    const captar = createCaptar({
      project: "support-bot",
    });
    ```
  </Tab>
</Tabs>

## Next reads

<Cards>
  <Card title="Sessions and budgets" href="/core-concepts/sessions-and-budgets">
    Understand reservation, finalization reserve, and session state.
  </Card>

  <Card title="OpenAI wrapping" href="/core-concepts/openai-wrapping">
    Learn how request estimation, policy checks, and spans are attached to calls.
  </Card>
</Cards>
