ZuploZuplo
LoginStart for Free
  • Documentation
  • API Reference
Introduction
Getting Started
    Develop on the web portal
      1 - Setup Your Gateway2 - Rate Limiting3 - API Key Auth4 - Deploy5 - Dynamic Rate LimitingDynamic MCP Server - Quickstart
    Develop locally with the CLI
      1 - Setup Your Gateway2 - Rate Limiting3 - API Key Auth4 - Deploy5 - Dynamic Rate LimitingDynamic MCP Server - Quickstart
Concepts
Development
Policies
    Policy Catalog
    Authentication
    Authorization
    MCP Authorization
    Security & Validation
    Metrics, Billing & Quotas
    Testing
    Request Modification
    Response Modification
    Upstream Authentication
      OAuth AuthenticationSet Upstream API KeyUpstream Azure AD Service AuthUpstream GCP Service AuthUpstream GCP Federated AuthUpstream GCP Self-Signed JWTUpstream Firebase Admin AuthUpstream Firebase User AuthUpstream Zuplo JWT
    Archival
    GraphQL
    Other
    Guides
Handlers
API Keys
Rate Limiting
MCP Server
MCP Gateway
AI Gateway
Developer Portal
Monetization
Deploying & Source Control
Analytics
Observability
Networking & Infrastructure
Account Management
Programming API
Build with AI
Zuplo CLI
Migration Guides
Platform LimitsSecuritySupportTrust & ComplianceChangelog
powered by Zudoku
Upstream Authentication

Set Upstream API Key Policy

The set upstream API key policy attaches a single header (by default Authorization) to the incoming request so it can be forwarded to your upstream service. It is a focused version of the set headers policy intended for the common case of authenticating Zuplo to an upstream API using a secret sourced from an environment variable.

Configuration

The configuration shows how to configure the policy in the 'policies.json' document.

config/policies.json
{ "name": "my-set-upstream-api-key-inbound-policy", "policyType": "set-upstream-api-key-inbound", "handler": { "export": "SetUpstreamApiKeyInboundPolicy", "module": "$import(@zuplo/runtime)", "options": { "header": "Authorization", "value": "Bearer $env(UPSTREAM_API_KEY)" } } }

Policy Configuration

  • name <string> - The name of your policy instance. This is used as a reference in your routes.
  • policyType <string> - The identifier of the policy. This is used by the Zuplo UI. Value should be set-upstream-api-key-inbound.
  • handler.export <string> - The name of the exported type. Value should be SetUpstreamApiKeyInboundPolicy.
  • handler.module <string> - The module containing the policy. Value should be $import(@zuplo/runtime).
  • handler.options <object> - The options for this policy. See Policy Options below.

Policy Options

The options for this policy are specified below. All properties are optional unless specifically marked as required.

  • header <string> - The name of the header to set on the request. Defaults to Authorization. Defaults to "Authorization".
  • value (required) <string> - The value of the header. Most commonly an environment variable reference such as Bearer $env(UPSTREAM_API_KEY) so the secret is sourced from your environment.
  • overwrite <boolean> - Overwrite the value if the header is already present in the request. Defaults to true.

Using the Policy

Many upstream APIs require an API key or bearer token to be passed in a header on every request. This policy is a focused version of the SetHeadersInboundPolicy that sets a single header (defaulting to Authorization) and is designed to be paired with an environment variable so the secret never lives in your policies.json.

The most common configuration sets a bearer token from an environment variable:

Code
{ "name": "set-upstream-api-key-inbound-policy", "policyType": "set-upstream-api-key-inbound", "handler": { "export": "SetUpstreamApiKeyInboundPolicy", "module": "$import(@zuplo/runtime)", "options": { "value": "Bearer $env(UPSTREAM_API_KEY)" } } }

You can also customize the header name. For example, if your upstream uses a custom header rather than Authorization:

Code
{ "name": "set-upstream-api-key-inbound-policy", "policyType": "set-upstream-api-key-inbound", "handler": { "export": "SetUpstreamApiKeyInboundPolicy", "module": "$import(@zuplo/runtime)", "options": { "header": "X-API-Key", "value": "$env(UPSTREAM_API_KEY)" } } }

By default the policy overwrites any header with the same name that was sent by the client. Set overwrite to false to preserve the incoming value when one is present.

Read more about how policies work

Edit this page
Last modified on June 26, 2026
OAuth AuthenticationUpstream Azure AD Service Auth
On this page
  • Configuration
    • Policy Configuration
    • Policy Options
  • Using the Policy
JSON
JSON
JSON