# Configure global headers

> Learn how to configure global headers in Fern SDKs. Set up API headers once as constructor parameters for automatic inclusion in all requests.

Your API may leverage certain headers for every endpoint or most endpoints.
These are called **global headers**.

## How it works for SDK users

Once you configure a global header (either automatically detected or manually
specified), Fern generates an SDK that accepts this as a constructor parameter.
Users can then provide the value once, and the generated SDK automatically
includes the header in all their API calls:

```python
import os

class Client:

  def __init__(self, *, apiKey: str):
```

## Specifying global headers

Fern automatically identifies headers that are used in every request, or the
majority of requests, and marks them as global. You can manually configure additional
global headers in either `api.yml` (Fern Definition) or `openapi.yml`.

<AccordionGroup>
  <Accordion title="OpenAPI">
    For OpenAPI specifications, you can configure global headers in two ways:

    #### Method 1: OpenAPI Spec Extension

    Add global headers directly to your OpenAPI spec using the `x-fern-global-headers` extension to label additional headers as global or to alias the names of global headers:

    ```yaml title="openapi.yml"
    x-fern-global-headers:
      - header: custom_api_key
        name: api_key
      - header: userpool_id
        optional: true
    ```

    #### Method 2: `generators.yml` Configuration

    Alternatively, you can add headers to the `api` block in your `generators.yml` file:

    ```yaml title="generators.yml"
    api:
      - openapi: ./path/to/openapi
        headers: 
          custom_api_key:
            name: api_key
            type: string
          userpool_id:
            name: userpool_id
            type: optional<string>
    ```

    For more information, see the [`generators.yml` reference documentation](/sdks/reference/generators-yml#headers).

    #### Client code

    Both of the above configurations produce the same client code:

    ```python
    import os

    class Client:

      def __init__(self, *, apiKey: str, 
                   userpoolId: typing.Optional[str])
    ```
  </Accordion>

  <Accordion title="Fern Definition">
    To specify headers that are meant to be included on every request:

    <CodeBlock title="api.yml">
      ```yaml {3}
      name: api
      headers:
        X-App-Id: string
      ```
    </CodeBlock>

    ### Global path parameters

    You can also specify path parameters that are meant to be included on every request:

    <CodeBlock title="api.yml">
      ```yaml
      name: api
      base-path: /{userId}/{orgId}
      path-parameters:
        userId: string
        orgId: string
      ```
    </CodeBlock>

    #### Overriding the base path

    If you have certain endpoints that do not live at the configured `base-path`, you can
    override the `base-path` at the endpoint level.

    ```yml imdb.yml {5}
    service: 
      endpoints: 
        getMovie: 
          method: POST
          base-path: "override/{arg}"
          path: "movies/{movieId}"
          path-parameters: 
            arg: string
    ```

    <Note>
      You cannot yet specify query parameters that are meant to be included on every request.
      If you'd like to see this feature, please upvote [this issue](https://github.com/fern-api/fern/issues/2930).
    </Note>
  </Accordion>
</AccordionGroup>