Skip to content
All topics

Domain

LLM API integration

Calling model provider APIs reliably: authentication, streaming, timeouts, retries, rate limits, errors and cost tracking.

0 of 15 articles published. Topics are listed in reading order: each comes after the topics it builds on.

Calling a model API

The request and response cycle of a hosted model API, end to end.

  1. The life of an LLM API requestComing soon

    Every hop from the user's click to the streamed answer, and where time and money are spent along the way.

    Fundamentals · Beginner

  2. Messages, roles and system instructionsComing soon

    How chat APIs structure a conversation, and what system, user and assistant messages are for.

    Fundamentals · Beginner

  3. Managing provider API keysComing soon

    Keeping keys on the server, scoping and rotating them, and detecting leaks.

    Security · Intermediate

  4. Streaming responses with server-sent eventsComing soon

    Relaying tokens to the browser as they arrive, handling disconnects, and assembling the final message.

    Implementation · Intermediate

  5. Structured output and schema validationComing soon

    Asking for JSON that matches a schema, validating it, and recovering when the model gets it wrong.

    Implementation · Intermediate

Reliable model calls

Keeping an application working when the provider is slow, overloaded or failing.

  1. Provider errors and how to classify themComing soon

    Which errors are worth retrying, which mean the request is wrong, and which mean stop.

    Fundamentals · Intermediate

  2. Timeouts for model callsComing soon

    Connect, first-token and total timeouts, and how streaming changes what a timeout means.

    Configuration · Advanced

  3. Retries with backoff and jitterComing soon

    Bounded retries that do not amplify an outage, and when a retry needs an idempotency key.

    Implementation · Advanced

  4. Working within provider rate limitsComing soon

    Request and token limits, reading rate-limit headers, and queueing work instead of failing it.

    Operations · Advanced

  5. Falling back to another model or providerComing soon

    Designing a fallback chain, handling behavioural differences between models, and knowing when not to fall back.

    Architecture · Production

Provider abstraction

Isolating the application from any one provider's SDK and quirks.

  1. Designing a model provider interfaceComing soon

    A small interface that hides provider differences without hiding the features you rely on.

    Architecture · Advanced

  2. Testing model integrations with fakesComing soon

    Deterministic fakes and recorded responses for unit and integration tests, and what they cannot catch.

    Implementation · Advanced

Usage and cost

Knowing what each call costs and keeping spend under control.

  1. Counting tokens and tracking cost per requestComing soon

    Recording input, output and cached tokens per request so cost can be attributed to features and tenants.

    Implementation · Intermediate

  2. Spending budgets and per-user quotasComing soon

    Enforcing daily budgets and per-user limits atomically, and failing in a way users understand.

    Operations · Production

  3. Batch APIs for offline workloadsComing soon

    When asynchronous batch processing fits, and how to track, retry and reconcile batch jobs.

    Implementation · Advanced