Usage reporting

Every successful TTS / STT call carries a complete picture of what just happened · units billed, credits charged, marginal cost, and the plan limits remaining · on the response itself. The same numbers flow through three surfaces so you can pick whichever fits your pipeline:

  1. Response headers (x-hakim-*) · copy them straight into a warehouse, a metrics platform, or your own audit log.
  2. JSON usage block · the STT batch response (response_format=json or verbose_json) embeds an OpenAI-shaped usage object inside the body.
  3. WebSocket frames · the STT realtime stream emits a session.created envelope with the snapshot, a transcription.done frame carrying the per-utterance usage block, and a periodic session.usage heartbeat for long sessions.

Two read-only endpoints expose the same data on demand:

  • GET /v1/limits · point-in-time snapshot of plan, period, credits, concurrency, and rate-limit. Cheap enough to poll every 30 s.
  • GET /v1/usage/events/:id · single event lookup. Dereference any x-request-id from a header into the row that contains the public model identifier and per-row credit / cost columns.

Response headers

HeaderMeaning
x-hakim-plan-idOrg's current plan slug.
x-hakim-environmentlive or test. Test keys (hk_test_…) skip the rest of the set.
x-hakim-usage-kindtts · stt_batch · stt_realtime · voice_clone · video_studio · llm_chat.
x-hakim-usage-unitsInteger units billed by this request.
x-hakim-usage-unit-typecharacters · seconds · count · credits · tokens.
x-hakim-usage-creditsCredits charged.
x-hakim-usage-cost-usdMarginal cost in USD, decimal string ("0.00" inside the bundle).
x-hakim-modelPublic model identifier (e.g. hakim-arab-v2, saree-v1.3).
x-hakim-period-startISO-8601 start of the billing period.
x-hakim-period-endISO-8601 end (exclusive) of the billing period.
x-hakim-credits-includedPlan bundle + active top-ups for the period.
x-hakim-credits-usedCredits consumed in the period so far.
x-hakim-credits-remainingeffective_limit − used, floored at zero.
x-hakim-credits-effective-limitBundle + overage allowance honouring the org's overage mode.
x-hakim-concurrency-limitPlan ceiling for in-flight requests.
x-hakim-concurrency-currentIn-flight request count at response time.

The x-ratelimit-* set (limit, remaining, reset) is unchanged from the rest of the API and is documented in the rate-limits guide.

Currency as a decimal string. x-hakim-usage-cost-usd is the string "0.04", not the number 0.04. JSON numbers are floats and rounding errors compound across millions of rows; warehouses can treat the string as DECIMAL(10,4) cleanly. Same convention for the cost_usd field in JSON / WS payloads.

JSON usage block (STT batch)

Set response_format=json (or verbose_json) on POST /v1/audio/transcriptions and the response body carries the canonical usage object alongside the transcript:

{
  "text": "مرحبا بكم في حكيم",
  "usage": {
    "request_id": "req_9b703d4c",
    "kind": "stt_batch",
    "units": 12,
    "unit_type": "seconds",
    "credits": 23,
    "cost_usd": "0.00",
    "model": "hakim-arab-v2",
    "billing_period_start": "2026-05-01T00:00:00Z",
    "billing_period_end": "2026-06-01T00:00:00Z"
  }
}

The shape is identical to the WebSocket transcription.done.usage payload and to the UsageBlock you'll get when you scrape the x-hakim-usage-* headers · one schema everywhere.

WebSocket frames (STT realtime)

On WSS /v1/audio/transcriptions/stream:

  • session.created carries usage_snapshot: LimitsSnapshot · the same shape returned by GET /v1/limits · so the very first frame the server emits already tells you how much budget you have for this session.
  • transcription.done carries usage: UsageBlock for the utterance that just finalised. Aggregate these for per-session totals.
  • session.usage is a periodic heartbeat (~30 s) carrying a fresh UsageBlock covering the cumulative session audio so a long-running meeting transcriber reports incrementally instead of only at close.

The contract is documented under the realtime tag in the API reference.

Endpoints

GET /v1/limits

Returns a LimitsSnapshot with the same blocks the x-hakim-credits-* / x-hakim-concurrency-* / x-ratelimit-* headers describe, plus the authoritative plan.overage_mode (which the header surface doesn't carry).

curl https://api.tryhakim.ai/v1/limits \
  -H "Authorization: Bearer $HAKIM_API_KEY"
{
  "generated_at": "2026-05-26T11:02:31Z",
  "organization_id": "org_2ab…",
  "plan": { "id": "scale", "name": "Scale", "overage_mode": "topup" },
  "period": {
    "start": "2026-05-01T00:00:00Z",
    "end": "2026-06-01T00:00:00Z"
  },
  "credits": {
    "included": 5000000,
    "used": 1234567,
    "remaining": 3765433,
    "effective_limit": 5000000
  },
  "concurrency": { "limit": 100, "current": 7 },
  "rate_limit": {
    "limit_per_minute": 3000,
    "remaining": 2998,
    "reset_at": "2026-05-26T11:03:00Z"
  }
}

GET /v1/usage/events/:id

Single-event detail lookup. Useful for dereferencing a header-scraped x-request-id after the fact:

curl https://api.tryhakim.ai/v1/usage/events/evt_a8d7… \
  -H "Authorization: Bearer $HAKIM_API_KEY"

The response is the same row shape as GET /v1/usage/events with one addition · model (lifted from the row's metadata), so a header scraped without x-hakim-model can still be reconciled.

SDK ergonomics

Node

The Node SDK parses the header set into a typed usage + limits object on every audio.speech.create() / audio.speech.stream() response. Drop it straight into your audit table:

import { HakimClient } from '@tryhakim/voice';

const hakim = new HakimClient({ apiKey: process.env.HAKIM_API_KEY });

const res = await hakim.audio.speech.create({
  model: 'saree-v1.3',
  voice: 'aya-narrator',
  input: 'مرحبا بكم',
});

console.log(res.usage); // { request_id, kind: 'tts', units, credits, cost_usd, model, ... }
console.log(res.limits); // { plan, period, credits, concurrency }

For dashboard tiles, call the snapshot endpoint directly:

const snapshot = await hakim.usage.limits();
const detail = await hakim.usage.event(res.usage!.request_id);

Python

The Python SDK exposes the same limits() + event(id) helpers:

from hakim import AsyncHakim

async with AsyncHakim(api_key=os.environ["HAKIM_API_KEY"]) as hakim:
    snapshot = await hakim.usage.limits()
    event = await hakim.usage.event("evt_a8d7…")

The transport returns an httpx.Response under the hood, so any field above can also be read directly from response.headers["x-hakim-usage-…"] if your pipeline already speaks raw HTTP.

Reporting recipe

Whatever ingestion path you prefer · S3 + an ETL job, Kafka topics, Splunk forwarders, a serverless function, an APM agent · the loop is the same:

  1. Wrap your HTTP client so every response is observed.
  2. Read the x-hakim-* headers and (for STT batch JSON) the usage block. Both contain the same fields; the JSON copy is convenient when you don't want to plumb headers through a worker queue.
  3. Append one row per request keyed by x-request-id. Schema is already stable · kind, units, unit_type, credits, cost_usd, model, billing_period_start, billing_period_end, plus the period + credits + concurrency snapshot fields you'd like to track over time.
  4. Aggregate later. Daily totals, top-N talkers, overage trajectory, and saturation alarms (credits_remaining < 10 %, concurrency_current ≥ concurrency_limit) are all single SELECT … GROUP BY queries against that one row.

A minimal Node middleware (works for any framework that returns a fetch-style Response):

import type { UsageBlock } from '@tryhakim/voice';

interface UsageRow {
  request_id: string;
  ts: string;
  kind: string;
  units: number;
  credits: number;
  cost_usd: string;
  model: string | null;
  period_start: string;
  period_end: string;
}

function rowFromResponse(res: Response): UsageRow | null {
  const kind = res.headers.get('x-hakim-usage-kind');
  const units = Number(res.headers.get('x-hakim-usage-units'));
  const credits = Number(res.headers.get('x-hakim-usage-credits'));
  const cost = res.headers.get('x-hakim-usage-cost-usd');
  const requestId = res.headers.get('x-request-id');
  if (!kind || !Number.isFinite(units) || !Number.isFinite(credits) || !cost || !requestId) {
    return null;
  }
  return {
    request_id: requestId,
    ts: new Date().toISOString(),
    kind,
    units,
    credits,
    cost_usd: cost,
    model: res.headers.get('x-hakim-model'),
    period_start: res.headers.get('x-hakim-period-start') ?? '',
    period_end: res.headers.get('x-hakim-period-end') ?? '',
  };
}

Pipe the resulting row into whatever sink fits · a streaming insert into Snowflake, a POST to your logging endpoint, an INSERT into Postgres, a Splunk HEC event. The shape doesn't care, and the same records back the GET /v1/usage/events endpoint so your reconciliation job has a server-side counterpart to cross-check against.

Notes on concurrency

The x-hakim-concurrency-* headers report the in-flight request count for the org at response time and the plan ceiling. v1 is visibility-only · the API exposes the numbers but doesn't 429 on over-cap requests yet. This forward-compatible contract means a future enforcement flip won't change the header shape, only its behaviour.

If you need a strict cap before the flip happens, gate calls on x-hakim-concurrency-current ≥ x-hakim-concurrency-limit in your own client. Reach out to your account team if you'd like enforcement enabled for your org early.