Skip to main content

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.

What this shows

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

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

Next reads