跳到导航

Configure global headers

以 Markdown 格式查看
You're viewing the legacy SDK docs

These pages cover SDK generation configured with generators.yml. New projects use sdk-config.yml, so see the Current version of this page for up-to-date guidance. To move an existing project, follow the SDK Config migration guide, which walks through fern sdk migrate, and review the sdk-config.yml reference.

If your API requires certain headers on every request (or most requests), you can configure them as global headers. Fern will generate an SDK that accepts these headers once in the client constructor and automatically includes them in all API calls.

Generated SDK behavior

Once you configure a global header, Fern generates an SDK that accepts the header value as a constructor parameter:

import os
class Client:
def __init__(self, *, apiKey: str):

SDK users provide the value once, and the generated SDK automatically includes the header in all requests.

Setting up global headers

Fern automatically identifies headers used in every request, or the majority of requests, and marks them as global. You can manually configure additional global headers in your API definition:

openapi.yml
x-fern-global-headers:
- header: custom_api_key
name: api_key
- header: userpool_id
optional: true

You can also pin a default value on a global header so the SDK sends it automatically when the caller doesn’t provide one.

For full configuration details, see Global headers in OpenAPI.