Skip to main content

APIKeyHeader

This defines the name of the header that should be provided in the request with the API key and integrates that into the OpenAPI documentation. It extracts the key value sent in the header automatically and provides it as the dependency result. But it doesn't define how to send that key to the client.

Attributes

AttributeTypeDescription
namestrHeader name.
scheme_name`strNone` = None
description`strNone` = None
auto_errorbool = TrueBy default, if the header is not provided, APIKeyHeader will automatically cancel the request and send the client an error; if set to False, the dependency result will be None instead.

Constructor

Signature

def APIKeyHeader(
name: str,
scheme_name: str | None = None,
description: str | None = None,
auto_error: bool = True
) - > null

Parameters

NameTypeDescription
namestrHeader name.
scheme_name`strNone` = None
description`strNone` = None
auto_errorbool = TrueIf True, missing headers result in an error; if False, the dependency result is None.

Signature

def APIKeyHeader(
name: str,
scheme_name: str | None = None,
description: str | None = None,
auto_error: bool = True
) - > null

Parameters

NameTypeDescription
namestrThe name of the HTTP header that should contain the API key.
scheme_name`strNone` = None
description`strNone` = None
auto_errorbool = TrueDetermines if the request should be automatically rejected with an error if the header is missing; set to False for optional authentication.