ZuploZuplo
LoginStart for Free
  • Documentation
  • API Reference
Getting Started
    Develop in the 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
API Management
    Overview
    API Keys
    Rate Limiting
    Caching
    GraphQL
    Monetization
    Policies
      Overview
      Authentication
      Authorization
      Security & Validation
      Metrics, Billing & Quotas
      Testing
      Request Modification
      Response Modification
      Upstream Authentication
        OAuth AuthenticationSet Upstream API KeyUpstream OAuth 2.0 Client Credentials AuthUpstream AWS Service AuthUpstream AWS Federated AuthUpstream Azure AD Service AuthUpstream GCP Service AuthUpstream GCP Federated AuthUpstream GCP Self-Signed JWTUpstream Firebase Admin AuthUpstream Firebase User AuthUpstream Zuplo JWT
      GraphQL
      Caching
      Other
      Guides
    Handlers
AI Gateway
MCP Gateway
MCP Server
Developer Portal
Development
Deploying & Source Control
Analytics
Observability
Networking & Infrastructure
Account Management
Programming API
Build with AI
Zuplo CLI
Migration Guides
Platform LimitsVersion Support PolicySecuritySupportTrust & ComplianceChangelog
powered by Zuplo
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.

Code
{ "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.

  • 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.
  • header <string> - The name of the header to set on the request. Defaults to Authorization. Defaults to "Authorization".
  • 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 September 17, 2026
OAuth AuthenticationUpstream OAuth 2.0 Client Credentials Auth
On this page
  • Configuration
    • Policy Configuration
    • Policy Options
  • Using the Policy
JSON
JSON
JSON