Developer reference

AgentAudit API & SDK

You don't call the HTTP API by hand. You wrap your existing LLM client and AgentAudit captures every prompt, completion, tool call, token, and cost automatically. The OpenAPI spec below is here so you can extend the SDK or generate a client in another language.

// 1. Wrap your OpenAI client — zero call-site changes
import OpenAI from "openai";
import { createAgentAudit } from "@agentaudit/sdk";

const aa     = createAgentAudit({ apiKey: process.env.AGENTAUDIT_KEY! });
const openai = aa.wrapOpenAI(new OpenAI());

await aa.withTrace(
  { agent_name: "billing-copilot", external_user_id: user.id },
  async () => {
    // every LLM + tool call inside is captured automatically
    return openai.chat.completions.create({
      model: "gpt-5.5",
      messages: [{ role: "user", content: q }],
    });
  },
);
// 2. Instrument arbitrary tools and any provider
import Anthropic from "@anthropic-ai/sdk";

const anthropic = aa.wrapAnthropic(new Anthropic());
const lookup    = aa.tool("lookup_invoice", async (id: string) => db.invoices.get(id));

// LangChain / LangGraph:
await chain.invoke(input, { callbacks: [aa.langchainCallbackHandler()] });

// Raw fetch to any provider (OpenRouter, Groq, Gemini, Mistral…):
const fetch2 = aa.wrapFetch();
await fetch2("https://api.openai.com/v1/chat/completions", { /* ... */ });