Developer DocsstableUpdated 2026-07-06

Gateway

Route AI provider traffic through Kadryn for runtime control, cost visibility, policy enforcement and traceable debugging.

Kadryn Gateway lets your application send AI provider requests through Kadryn instead of calling the provider directly.

Use it when you need runtime visibility, cost attribution, policy checks, budget caps, provider routing, traceability and production debugging for AI traffic.

Gateway is the inline path.

If you only want to send historical or externally captured usage into Kadryn, use Direct ingest instead.

What you will do

In this guide, you will:

  1. understand when to use Gateway;
  2. create or select a Kadryn API key;
  3. verify provider route readiness;
  4. send a test request through Gateway;
  5. attach project, feature, environment and tracing metadata;
  6. verify the request in Logs & Traces;
  7. handle common errors and retries.

When to use Gateway

Use Gateway when Kadryn must evaluate the request before or during provider execution.

Gateway is the right path for:

  • central request logging;
  • cost and token tracking;
  • project, feature and environment attribution;
  • budget caps and policy enforcement;
  • provider route readiness checks;
  • fallback and routing visibility;
  • runtime debugging in Logs & Traces;
  • production verification with trace IDs and request group IDs.

When not to use Gateway

Do not use Gateway when you only need offline usage import.

Use Direct ingest when:

  • traffic already went through another proxy;
  • you cannot place Kadryn inline yet;
  • you only need cost visibility after execution;
  • an external source already emits normalized usage events;
  • you are backfilling historical usage.

Gateway gives runtime control. Direct ingest gives observability without proxying traffic.

Request flow

  1. Your application sends the AI request to Kadryn Gateway.
  2. Kadryn authenticates the request with your Kadryn API key.
  3. Kadryn attaches workspace context from headers and API key metadata.
  4. Kadryn evaluates routing, policy and guardrail configuration.
  5. Kadryn forwards the request to the selected provider route.
  6. Kadryn records request, tokens, cost, status, latency and trace metadata.
  7. Your application receives the provider-compatible response.
  8. You inspect the event in Logs & Traces.

Gateway is the runtime entry point. Guardrails defines policies. Costs analyzes spend. Logs & Traces explains individual requests.

Base URL

https://gateway.kadryn.com/v1

For OpenAI-compatible chat completions:

POST https://gateway.kadryn.com/v1/chat/completions

Prerequisites

Before sending Gateway traffic:

  • create a Kadryn API key;
  • configure at least one provider key;
  • verify the provider route is ready;
  • identify the project and environment;
  • decide which metadata your policies require;
  • decide how your service handles retries and idempotency.

Quickstart request

export KADRYN_API_KEY="kadryn_live_..."

curl https://gateway.kadryn.com/v1/chat/completions \
  -H "Authorization: Bearer $KADRYN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Kadryn-Project: prod-api" \
  -H "X-Kadryn-Feature: support-agent" \
  -H "X-Kadryn-Environment: prod" \
  -d '{
    "model": "gpt-4.1-mini",
    "messages": [
      {
        "role": "user",
        "content": "Hello from Kadryn Gateway"
      }
    ]
  }'

Production request

curl https://gateway.kadryn.com/v1/chat/completions \
  -H "Authorization: Bearer $KADRYN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Kadryn-Project: billing-api" \
  -H "X-Kadryn-Feature: invoice-assistant" \
  -H "X-Kadryn-Environment: prod" \
  -H "X-Kadryn-Request-Group-Id: invoice-run-2026-07-06-001" \
  -H "Idempotency-Key: invoice-run-2026-07-06-001:step-01" \
  -H "traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" \
  -d '{
    "model": "gpt-4.1-mini",
    "messages": [
      {
        "role": "system",
        "content": "You are a support assistant for billing questions."
      },
      {
        "role": "user",
        "content": "Summarize the latest invoice status for this customer."
      }
    ],
    "temperature": 0.2
  }'

Required headers

HeaderRequiredDescription
AuthorizationYesKadryn API key using Bearer.
Content-TypeYesUse application/json.
X-Kadryn-ProjectRecommendedProject slug or ID for attribution.
X-Kadryn-FeatureRecommendedFeature, workflow or agent producing the request.
X-Kadryn-EnvironmentRecommendedEnvironment such as dev, staging, prod, test or preview.

Policies may require metadata that is technically optional.

HeaderUse it for
X-Kadryn-TeamTeam ownership and reporting.
X-Kadryn-Cost-CenterFinance allocation and chargeback.
X-Kadryn-Budget-OwnerOwnership-based governance.
X-Kadryn-CustomerCustomer-level unit economics.
X-Kadryn-TenantTenant-level attribution.
X-Kadryn-WorkflowWorkflow or job tracking.
X-Kadryn-AgentAgent-level attribution.
X-Kadryn-Request-Group-IdGroup related provider calls into one business operation.
Idempotency-KeySafe retry behavior.
traceparentDistributed tracing correlation.

Gateway readiness

Gateway readiness can appear as:

StateMeaningWhat to do
readyGateway can receive traffic and route to configured providers.Send traffic and verify Logs & Traces.
waiting_for_trafficGateway is configured but no traffic has been observed.Generate a test command or send a request.
missing_api_keyNo usable Kadryn API key is available.Create an API key.
degradedAt least one route, key or runtime signal needs attention.Review routes, provider keys and Logs & Traces.

Provider route readiness

StateMeaningNext step
readyProvider route is configured and usable.Send traffic.
needs_provider_keyA provider key is missing.Add a provider key.
provider_key_errorA configured provider key fails validation or usage.Fix or rotate the key.
untestedThe route has not been verified.Send a test request.

Verify in Logs & Traces

After sending a request, open:

Developers → Logs & Traces

Search by:

  • trace ID;
  • request group ID;
  • project;
  • feature;
  • environment;
  • provider;
  • model;
  • status;
  • fallback usage;
  • synthetic traffic.

Failure handling

Failure classRetry?What to do
Authentication errorNoCheck the Kadryn API key.
Authorization errorNoCheck role, plan and workspace access.
Validation errorNoFix payload or headers.
Policy blockNoInspect the decision and update metadata or policy.
Provider key errorNoFix or rotate the provider key.
Provider errorSometimesFollow provider-specific retry rules.
Rate limitYesUse backoff and preserve idempotency.
TimeoutYesRetry with idempotency.
Server errorYesRetry with bounded backoff.

Retry rules

For retryable failures:

  1. keep the same Idempotency-Key;
  2. keep the same X-Kadryn-Request-Group-Id;
  3. preserve or link the same trace context;
  4. use exponential backoff;
  5. stop after a bounded number of attempts.

Security notes

Do:

  • keep Gateway credentials server-side;
  • use separate keys per environment where possible;
  • rotate keys regularly;
  • preserve trace IDs;
  • redact sensitive payloads when required.

Do not:

  • expose Kadryn API keys in the browser;
  • log Authorization headers;
  • put secrets in URLs;
  • send provider API keys in metadata.

Production checklist

  • Kadryn API key exists.
  • Provider key exists.
  • Provider route is ready.
  • API key is server-side only.
  • Project metadata is sent.
  • Feature metadata is sent.
  • Environment metadata is sent.
  • Retryable requests use idempotency keys.
  • Tracing is propagated.
  • Logs & Traces show test traffic.
  • Policy blocks are understood.