Gateway Configuration

Example YAML policies and runtime environment variables for AI Gateway.

AI Gateway uses a YAML policy to configure the upstream LLM, scanners, profiles, and request routing. In a Helm deployment, manage this policy through the chart values and gateway ConfigMap. Cedar authorization policy is retrieved from Policy.

The examples below are complete minimal policies. They use a local regex scanner so they do not require a remote scanner service. Choose one upstream configuration for the deployed policy.

OpenAI-Compatible Upstream

Set FG_UPSTREAM_API_KEY in the gateway environment, then use this policy as the YAML policy value:

version: "1.0"
settings:
  default_action: block
  timeout_ms: 5000
  fail_open: false
upstream:
  url: "https://api.openai.com/v1"
  protocol: openai
  headers:
    Authorization: "Bearer ${FG_UPSTREAM_API_KEY}"
scanners:
  prompt-injection:
    type: regex
    patterns:
      - "ignore previous instructions"
      - "disregard your system prompt"
profiles:
  default-protection:
    inbound:
      scanners: [prompt-injection]
      on_reject: block
    outbound:
      scanners: []
      on_reject: block
routing:
  - default: default-protection

The OpenAI SDK client key is not used as the upstream credential by this configuration; the gateway supplies the key from FG_UPSTREAM_API_KEY.

Anthropic Upstream

For an Anthropic upstream, use this complete policy and set FG_UPSTREAM_API_KEY to the Anthropic key:

version: "1.0"
settings:
  default_action: block
  timeout_ms: 5000
  fail_open: false
upstream:
  url: "https://api.anthropic.com"
  protocol: anthropic
  headers:
    x-api-key: "${FG_UPSTREAM_API_KEY}"
scanners:
  prompt-injection:
    type: regex
    patterns:
      - "ignore previous instructions"
      - "disregard your system prompt"
profiles:
  default-protection:
    inbound:
      scanners: [prompt-injection]
      on_reject: block
    outbound:
      scanners: []
      on_reject: block
routing:
  - default: default-protection

Important: In the current gateway image, the Anthropic protocol forwards the client’s x-api-key upstream. Provide a valid Anthropic API key in the Anthropic client. This differs from the OpenAI configuration above, where the gateway supplies the upstream key.

External Identity Provider

Configure trusted JWT issuers in the file identified by FG_IDP_CONFIG_PATH. For an example issuer registry and setup steps, refer to External IdP Setup. Requests carry the caller’s JWT in the header specified by FG_PRINCIPAL_TOKEN_HEADER, which defaults to x-user-auth.

Environment Variables

All gateway environment variables use the FG_ prefix. The following reference lists the runtime settings used by the gateway and the upstream-key variable used by the policy and chart. The Helm chart can provide deployment-specific values that differ from the application defaults.

VariableApplication defaultDescription
FG_HOST0.0.0.0Address on which the gateway listens.
FG_PORT8080Port on which the gateway listens.
FG_POLICY_PATHpolicy.yamlPath to the YAML policy file.
FG_POLICY_ENGINEhybridPolicy engine mode: yaml, cedar, or hybrid.
FG_LOG_LEVELINFOLog level: DEBUG, INFO, WARNING, or ERROR.
FG_LOG_FORMATjsonLog format: json or cef.
FG_LOG_METADATAtrueInclude request metadata in structured logs.
FG_LOG_HMAC_ENABLEDfalseEnable HMAC integrity signatures on log entries.
FG_LOG_HMAC_KEYUnsetHMAC signing key; required when HMAC signing is enabled.
FG_MAX_STREAM_BUFFER_MB10Maximum streaming response buffer size in MB.
FG_MAX_REQUEST_BODY_MB10Maximum request body size in MB.
FG_LATENCY_BUCKETSEmptyOptional comma-separated Prometheus latency histogram buckets in milliseconds.
FG_RATE_LIMIT_RPS0 (disabled)Per-profile request rate limit.
FG_RATE_LIMIT_BURST0Rate-limit burst allowance; 0 uses the configured requests-per-second limit.
FG_ADMIN_TOKENEmpty (disabled)When set, protects admin endpoints with a bearer token.
FG_POLICY_SYNC_URLRequiredPolicy endpoint used to retrieve Cedar policy. Startup fails if this value is missing.
FG_POLICY_POLL_INTERVAL_S0Background Policy refresh interval in seconds. The Helm deployment sets this to 60.
FG_POLICY_SYNC_TIMEOUT_S10Timeout in seconds for an individual Policy fetch.
FG_DRAIN_TIMEOUT_S10Graceful shutdown drain timeout in seconds.
FG_ENFORCE_TLSfalseRequire HTTPS for scanner endpoints on non-loopback hosts.
FG_PRINCIPAL_TOKEN_HEADERx-user-authRequest header containing the caller’s identity JWT.
FG_IDP_CONFIG_PATHidp.yamlPath to the external IdP trust registry.
FG_VERIFY_TOKENtrueVerify JWT signatures and expiration against the IdP registry. Keep enabled in production.
FG_UPSTREAM_API_KEYUnsetUpstream API key referenced by policy configuration; use the appropriate provider’s key.

Do not place secrets in policy files committed to source control or in command history. Supply secret values through the deployment’s approved secret-management mechanism. For the OpenAI-compatible default upstream, use an OpenAI key; if one is not available at installation time, use a placeholder and replace it before sending requests to the upstream service.

Last modified : October 29, 2026