Skip to content

Commit 8fcf2f0

Browse files
feat: add CF Gateway auth header to custom OpenAI-compatible client
When CF_GATEWAY_AUTH_TOKEN is set, inject cf-aig-authorization header into the custom client so CF Gateway-proxied custom providers (e.g. custom-ollama) authenticate correctly at the gateway layer.
1 parent 32af03a commit 8fcf2f0

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/utils/clients.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,13 @@ def _get_effective_temperature(temperature: float | None) -> float | None:
268268
CLIENTS["openai"] = AsyncOpenAI(**_openai_kwargs)
269269

270270
if settings.LLM.OPENAI_COMPATIBLE_API_KEY and settings.LLM.OPENAI_COMPATIBLE_BASE_URL:
271+
_custom_headers: dict[str, str] = {}
272+
if settings.LLM.CF_GATEWAY_AUTH_TOKEN:
273+
_custom_headers["cf-aig-authorization"] = f"Bearer {settings.LLM.CF_GATEWAY_AUTH_TOKEN}"
271274
CLIENTS["custom"] = AsyncOpenAI(
272275
api_key=settings.LLM.OPENAI_COMPATIBLE_API_KEY,
273276
base_url=settings.LLM.OPENAI_COMPATIBLE_BASE_URL,
277+
default_headers=_custom_headers if _custom_headers else None,
274278
)
275279

276280
# Cloudflare AI Gateway (OpenAI-compatible universal endpoint)

0 commit comments

Comments
 (0)