Azure API Management Documentation

Set Header Policy

The <set-header> policy adds a new HTTP header or overwrites an existing one in the request or response. It is commonly used to inject authentication tokens, control caching, or pass custom metadata between services.

Syntax

<set-header name="header-name" exists-action="override|skip">
    <value>header-value</value>
</set-header>

Attributes

Example: Add Authorization Header

This example adds an Authorization header to every inbound request using a static token.

<inbound>
    <base>
        <set-header name="Authorization" exists-action="override">
            <value>Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...</value>
        </set-header>
    </base>
</inbound>

Dynamic Values

Headers can be set using expressions, variables, or policy transformations.

<set-header name="X-Request-ID" exists-action="override">
    <value>@(Guid.NewGuid().ToString())</value>
</set-header>

Usage Notes

See Also