Overview
api_key_tool_factory builds tools
for any API that authenticates with static headers. No credential provider, no
refresh flow — just header injection.
Use oauth_tool_factory instead when
the token is fetched or refreshed per call.
Design
- Simple — one dictionary of headers
- Flexible — single or multiple auth headers
- Overridable — set defaults on the factory, override per tool
- Checked — an empty header value is rejected at build time, not at the first 401
Basic usage
Single header (most common)
scraper_client.py
Multiple headers
multi_header_client.py
Bearer token
bearer_client.py
Per-tool overrides
Different endpoints can use different keys:per_tool_keys.py
Signature
Errors
- Empty header value, on the factory or a tool ->
DeclarationErrorat build time - No headers on either the factory or the tool ->
DeclarationErrornaming the tool 401from the API ->CredentialError(declarecredential_statuses={401, 403}if the API means “your token” by 403 too — most mean “not allowed”, which is anAPIError)- Any other
>= 400->APIErrorcarrying the status and a body excerpt