Technical Guide

LLMjacking Detection: Using AI Cost Spikes as a Signal for Stolen API Keys

A cost spike is a prompt to investigate, not proof of compromise. To separate LLMjacking from runaway agents, misconfiguration, or real growth, attribute the spend to a specific key, identity, and workload, then compare origin, model mix, timing, and volume against that workload's baseline. If the pattern does not fit, contain at the level of the single key or agent identity, rotate, and investigate how the credential was exposed.

From cost spike to containment: the triage sequence

  1. Detect

    Alert on usage deviations, not only on invoice totals.

  2. Attribute

    Trace spend to a key, identity, workload, or agent.

  3. Contain

    Throttle or revoke one credential without stopping others.

  4. Prevent

    Scope identities and enforce budgets and policy at runtime.

Differential diagnosis: malicious or operational?

A cost spike is an ambiguous signal. It may point to LLMjacking and a stolen API key, but it may equally come from a runaway agent, misconfiguration, or real growth. Once the spend is attributed to a specific key, identity, and workload, compare the following against that workload's baseline:

  • Origin: where the requests come from.
  • Model mix: which models are being called.
  • Timing: when the requests occur.
  • Volume: how much is being consumed.

If the pattern does not fit the workload, contain at the level of the single key or agent identity, rotate the credential, and investigate how it was exposed.

Telemetry needed for attribution

Attribution depends on being able to trace LLM spend to a specific key, identity, workload, or agent. Baseline and alert on these signals:

  • Token volume
  • Model mix
  • Request origin
  • Time of day
  • Unfamiliar models

Log policy decisions on model and tool calls in a form that supports incident investigation.

Prevention and runtime controls

Start with identity

Billing alerts are after-the-fact signals. They are useful, but they report spend that has already occurred. Prevention starts with identity: give each workload and agent its own credential, avoid shared keys, scope permissions to the models and tools it needs, and prefer short-lived credentials where the platform supports them. Add secret scanning to repositories and pipelines so leaked keys are found before others find them.

Limit the damage a valid credential can do

Runtime controls then limit the damage a valid credential can do. Per-key and per-agent budgets and rate limits cap exposure, and policy enforcement on model and tool calls blocks requests outside an identity's approved scope.

Tradeoff: tight limits can throttle legitimate bursts, so start in monitor mode, set thresholds above observed baselines, and route exceptions through an approval step.

Evaluation questions for your environment

  • Can we attribute LLM spend to a specific key, identity, workload, or agent, and at what granularity?
  • Which signals do we baseline and alert on: token volume, model mix, request origin, time of day, unfamiliar models?
  • Can we revoke or throttle one key or agent identity without disrupting other workloads?
  • Do we enforce per-key and per-agent budgets and rate limits at runtime, rather than relying only on billing alerts?
  • Are policy decisions on model and tool calls logged in a form that supports incident investigation?

Review your runtime controls for LLM and agent access

Discuss how scoped agent identities, runtime policy enforcement, and audit logging fit your detection and containment process.

Talk to an Expert