← Blog

Claude API Audit Log: Tracking Requests Per Key

2026-10-15 · 5 min read · SubToAPI Team

If you're searching for "Claude API audit log tracking requests," you're probably trying to answer one of two questions: who called the API and when, or what exactly was sent and received for a given request. Anthropic's raw API doesn't give you much of either out of the box — there's no per-key request log in the console beyond aggregate usage, and nothing that ties a specific completion back to a specific user, feature, or customer in your product.

This article covers what you actually need to log for a usable audit trail, how to implement it yourself with middleware, and where a proxy layer like SubToAPI removes most of the work.

Why you need an audit log in the first place

Three recurring reasons come up for teams building on the Claude API:

None of this is optional once you have more than one developer or one customer-facing feature touching the API. The question is whether you build it yourself or use a layer that already does it.

What a real audit log needs to capture

A request log that's actually useful for debugging or compliance should record, per call:

Notice what's not on that list by default: full prompt and response bodies. Logging those raises its own data-retention and PII questions, so decide upfront whether you log full payloads, hashed payloads, or metadata only. Many teams log metadata always and full payloads only in a short-lived debug buffer.

Building your own audit log around the API

If you're calling the Anthropic API directly, the audit log has to live in your own middleware — there's nothing server-side that attributes a request to a specific internal actor. A minimal version looks like this:

async function callClaudeWithAudit({ userId, feature, messages, model }) {
  const start = Date.now();
  const requestId = crypto.randomUUID();

  try {
    const res = await fetch("https://api.anthropic.com/v1/messages", {
      method: "POST",
      headers: {
        "x-api-key": process.env.ANTHROPIC_API_KEY,
        "anthropic-version": "2023-06-01",
        "content-type": "application/json",
      },
      body: JSON.stringify({ model, messages, max_tokens: 1024 }),
    });
    const data = await res.json();

    await logAuditEvent({
      requestId,
      userId,
      feature,
      model,
      status: res.status,
      inputTokens: data.usage?.input_tokens,
      outputTokens: data.usage?.output_tokens,
      durationMs: Date.now() - start,
    });

    return data;
  } catch (err) {
    await logAuditEvent({ requestId, userId, feature, model, status: "error", error: String(err) });
    throw err;
  }
}

This works, but you're now maintaining your own logging table, your own retention policy, and — critically — your own key management if you want per-user or per-customer attribution instead of one shared key. That's a non-trivial amount of infrastructure for what should be a secondary concern.

Where per-key tracking actually solves the problem

The cleanest way to get audit-grade visibility without building it yourself is to issue a separate application API key per consumer — per customer, per internal team, per environment — rather than sharing one key everywhere. That's the core idea behind SubToAPI: you get Claude access through a standard HTTPS API, but each sub_live_... key is its own trackable identity with its own usage metadata.

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Summarize this ticket."}]
  }'

Because every request flows through a scoped key, you get request and token tracking per key by default — no custom middleware required. That's enough for most audit asks: "show me who used Claude, how much, and when" is answered by looking at usage against a specific key rather than parsing shared application logs. If your team has multiple seats, each person or service can get their own key, which maps cleanly onto the "who did what" requirement that compliance reviews actually ask for. See the quickstart for setup and the messages and streaming docs for request formats, including tool use if your audit scope needs to cover tool-calling requests specifically.

A practical checklist

If you're setting up audit logging for Claude API usage today, work through this in order:

  1. Stop sharing one key everywhere. Issue one key per consumer (customer, feature, environment, or team member).
  2. Decide payload retention policy first. Metadata-only by default; full payloads in a short, explicitly-scoped debug window if you need them.
  3. Log token usage and latency per request, not just success/failure — cost spikes and slow responses are usually the first signal of an incident.
  4. Correlate with your own request IDs so support tickets and internal logs can be joined to the Claude-side record.
  5. Review retention against your actual compliance requirement — "we log it forever" is rarely the right answer, and neither is "we don't log it at all."

Whether you build this with your own middleware or route requests through keys that already carry per-key usage metadata, the goal is the same: being able to answer "who called Claude, with what, and when" in under a minute instead of grepping logs during an incident.

Questions

Does Anthropic's API provide a built-in audit log? Not a per-request audit trail tied to internal users. The console shows aggregate usage and billing, but attributing individual requests to a specific person, customer, or feature is left to you.

What's the minimum data I should log for compliance purposes? Timestamp, requesting identity (key or user ID), model, token counts, and request outcome. Full prompt/response bodies are optional and should follow an explicit retention policy, not be logged indefinitely by default.

Is issuing one API key per user or customer overkill? No — it's usually the single biggest simplification. Per-key tracking turns "who used the API" from a logging project into a dashboard lookup, which is exactly what tools like SubToAPI are built around.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →