Documentation

First governed request, without guessing the order.

Connect a provider, create a route alias, issue a workload key, observe the decision, then enforce only after you understand the result.

  • OpenAI-compatible quickstarts
  • Anthropic Messages and streaming
  • CLI and agent workload separation
Working sandbox capture
Applications call an alias; operators own the supply path.The real route console exposes strategy, compatible targets, current eligibility, and the model alias used by clients.
Choose the correct surface

Administrator, application, and staff access are separate.

Current production endpoint

Use api.aigatewayhq.com for every governed request.

The OpenAI-compatible base URL is https://api.aigatewayhq.com/v1. Anthropic clients use https://api.aigatewayhq.com. If an older local profile or copied example references aigateway.sh, replace that hostname and issue a current workload key; do not reuse a legacy credential.

Quickstart

Five deliberate steps

  1. Add a provider credential

    The secret is encrypted before storage and never returned. Start with a restricted test account.

  2. Create a model alias

    Map company-approved-fast to one or more compatible provider targets.

  3. Choose initial routing behavior

    Start with configured-cost ranking or priority-and-weight routing. Inspect the created route and policy before enforcement.

  4. Issue a gateway key

    The key is shown once and belongs in your secrets manager, CI identity, or local keychain.

  5. Send and inspect

    Make a request and review identity, policy reason, route, reserved estimate, supported provider-reported usage, and timing. The customer overview also allocates its latest retained request window by workload, environment, client, data class, provider account, route, or model.

curl https://api.aigatewayhq.com/v1/responses \
  -H "Authorization: Bearer $AIGHQ_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: deploy-job-123" \
  -d '{"model":"company-approved-fast","input":"Hello"}'
The mental model

Six concepts explain the whole gateway.

An application sends one request. AI Gateway HQ identifies the caller, checks the rules and budget, selects an eligible model, and records a safe decision trail. These are the controls an administrator configures.

01

Scope

Who is asking, and where?

Organization, environment, workload, principal, and gateway-key scopes let one rule apply broadly or to one specific caller.

02

Route pool

Where may this request run?

A stable model alias points to compatible provider, model, and credential targets. Applications keep the alias while operators change the supply path.

03

Policy

Is this request allowed?

Policies combine caller identity, environment, attributes, and routes to decide whether a request can run and which targets are eligible.

04

Guardrail

What content and tools may cross?

Guardrails can observe or block request signals before spend, then inspect complete non-streaming JSON output and proposed tool calls before release.

05

Budget

Can the caller spend now?

Organization and key allowance is reserved atomically before the provider call, so simultaneous traffic cannot race past a hard ceiling.

06

Evidence

What can an operator prove later?

The ledger retains identity, reason codes, route, timing, and supported usage metadata—not prompt, response, tool argument, or tool-result payloads.

Administrator details: safe changes, output inspection, and retries

Configuration lifecycle

Route, policy, guardrail, and budget edits are versioned and reject stale browser state. Disable is immediate. Re-enable and restore validate current dependencies; restore creates a reasoned new version rather than rewriting prior evidence. Protected deletion refuses to break an active reference.

Response and tool enforcement

Complete JSON output can be checked for local secret and PII signals, redacted at matched string values, blocked, or validated against a bounded Draft 2020-12 JSON Schema. Tool profiles apply deny-overrides-allow rules to names, types, MCP hosts or connectors, and inventory size, then verify that every emitted call was offered and remains authorized.

Enforcing output or tool inspection requires stream=false so uninspected bytes cannot escape. Tool hosts still own user approval, credentials, argument validation, sandboxing, and execution.

Safe retries and retained data

A unique Idempotency-Key prevents duplicate forwarding for 24 hours without storing model output. Raw guardrail expressions and schemas remain in tenant-private configuration history; audit evidence uses fingerprints and omits endpoint paths, query strings, and authorization headers.

Runtime API

POST /v1/responsesPOST /v1/chat/completionsPOST /v1/messagesPOST /v1/embeddingsGET /v1/models

Send a unique Idempotency-Key on retryable jobs. Replays return conflict metadata rather than retaining and replaying model output.

Choose a client integration
For developers, CLIs, and agents

Keep the SDK. Change the boundary.

Your organization administrator issues the gateway key and model alias. Put the key in a local keychain, CI secret, or workload secret manager—never in source control. The examples below use the public production origin; replace it only for an approved private deployment or local sandbox.

OpenAI-compatible clients

Use Responses, chat completions, embeddings, Codex-compatible tools, or OpenCode with the governed base URL.

from openai import OpenAI

client = OpenAI(
    base_url="https://api.aigatewayhq.com/v1",
    api_key=os.environ["AIGHQ_API_KEY"],
)

result = client.responses.create(
    model="company-approved-fast",
    input="Summarize the incident timeline",
)
Anthropic-compatible clients

Use Messages and streaming through the same policy, budget, route, and evidence boundary.

import anthropic

client = anthropic.Anthropic(
    base_url="https://api.aigatewayhq.com",
    api_key=os.environ["AIGHQ_API_KEY"],
)

message = client.messages.create(
    model="company-approved-fast",
    max_tokens=512,
    messages=[{"role": "user", "content": "Explain the change"}],
)
Gateway keys identify workloads, not providers.

Use separate keys for local development, CI, production services, and unattended agents so budgets and emergency revocation remain precise.

All integrations

Security defaults

Production refuses development authentication, in-memory storage, weak key material, missing OIDC, missing KMS, and non-HTTPS public URLs. Authentication, tenant resolution, credential access, client-context signatures, and explicit policy denial fail closed.

Security operations

Deliver control changes without exporting AI content.

Security and gateway administrators can add up to five customer-owned HTTPS destinations under Audit webhooks. Each destination receives administrative event metadata—who changed what, when, the resource identity, request correlation, and the audit chain hash. Prompt and response bodies, configuration snapshots, provider credentials, tool arguments, and tool results are excluded.

  1. Add a dedicated receiver

    Use a public DNS hostname on HTTPS port 443. Private addresses, IP literals, embedded credentials, query strings, redirects, and unsafe DNS answers are rejected.

  2. Store the short-lived secret result

    Normal reads never expose the signing secret. Put it in the receiver's secret manager. An interrupted console action can safely recover the same committed result for 15 minutes; after that, rotate if it was lost or exposed.

  3. Verify before parsing

    Reject stale timestamps, sign the exact raw bytes, compare in constant time, and deduplicate the delivery ID. A successful receiver should return any 2xx status.

  4. Review delivery evidence

    Delivery is at least once. The console shows bounded status, attempt count, HTTP status, and reason code for 90 days; authorized operators can replay a terminal delivery.

import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyAIGHQ(rawBody, headers, secret) {
  const signature = headers.get("aighq-webhook-signature") ?? "";
  const values = Object.fromEntries(
    signature.split(",").map((part) => part.split("=", 2)),
  );
  if (!/^\d+$/.test(values.t ?? "") || !/^[0-9a-f]{64}$/.test(values.v1 ?? "")) return false;
  if (headers.get("aighq-webhook-timestamp") !== values.t) return false;
  if (Math.abs(Date.now() / 1000 - Number(values.t)) > 300) return false;

  const mac = createHmac("sha256", secret);
  mac.update(values.t + ".", "utf8");
  mac.update(rawBody); // exact bytes, before JSON parsing
  const expected = mac.digest();
  const received = Buffer.from(values.v1, "hex");
  return received.length === expected.length && timingSafeEqual(received, expected);
}

The signature header is AIGHQ-Webhook-Signature: t=…​,v1=…​. The HMAC-SHA-256 input is timestamp + "." + rawBody. Use Idempotency-Key or AIGHQ-Webhook-ID as the deduplication key. Native Splunk HEC, Sentinel, Chronicle, Datadog, and checkpointed object-storage adapters are not currently included; the available boundary is a generic signed HTTPS event.

Destination changes and terminal replays require a unique control-plane Idempotency-Key. The console reuses it after a network error. A payload-free 24-hour result marker commits atomically with the audited change; secret recovery is limited to 15 minutes and the exact unchanged destination version. Reusing a key with changed input is rejected.