Support Azure API Management cookie-based session affinity

Resolved 💬 1 comment Opened Dec 30, 2025 by eberkut Closed Feb 23, 2026

What feature would you like to see?

I would like Codex CLI's HTTP client to support HTTP cookies and reuse a client across related calls, so it works with Azure API Management's cookie-based session affinity for Azure OpenAI v1.

Concretely, when Azure API Management sets a session cookie on a call (for example POST /openai/v1/responses), Codex CLI should store that cookie and send it back as Cookie: ... on follow-up calls in the same session (same base URL / provider / auth). This allows Azure API Management to keep all v1 Responses calls for a conversation or response id on the same backend account, as expected by the platform.

Additional information

Today Codex's Rust HTTP stack uses reqwest with features = ["json", "stream"] (no cookies feature, no cookie jar). build_reqwest_client() (core/src/default_client.rs) builds a reqwest::Client with default headers and user agent, but does not enable cookie storage. ModelClient creates a new transport and client for each call; for example in stream_chat_completions, stream_responses_api, and compact_conversation_history it does let transport = ReqwestTransport::new(build_reqwest_client()); let client = Api...Client::new(transport, api_provider, api_auth);.

As a result, Codex never stores Set-Cookie values from Azure API Management and never sends a Cookie header on subsequent calls. Each request uses a fresh client with no shared cookies or connections. In setups with multiple Azure OpenAI accounts in a pool, follow-up v1 Responses calls (for example GET /responses/{id} after store=true) may hit a different backend account and fail because the state is not there, even though Azure API Management is configured for cookie-based affinity.

Azure's guidance for Azure API Management with OpenAI v1 (especially the Responses and Assistants APIs) relies on a session cookie for stateful and multi-turn flows (see https://learn.microsoft.com/en-us/azure/api-management/backends#session-awareness). Codex is otherwise a good fit for talking to Azure API Management fronting LLM APIs, but without cookie handling it cannot follow this pattern, so these scenarios do not work as intended.

For comparison, the OpenAI Python SDK uses a shared httpx.Client under the hood, so in the same Azure API Management setup the session cookie is handled automatically and these v1 Responses flows behave as expected.

A couple of changes would make Codex friendlier to this setup:

  • Enable the cookies feature on reqwest and turn on a cookie store in build_reqwest_client().
  • Reuse a reqwest::Client or ReqwestTransport per (provider, base_url, auth) instead of per call, so cookies and connections are shared.

Even a simple sticky session mode that keeps one client (with cookies) across calls to the same endpoint would be enough to support Azure API Management's cookie-based session affinity for v1 Responses.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗