Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)
Python
Restore OpenAI subscription generation compatibility (#1326)
Ali Khokharfccf572746a1
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 0ea25948..b73b1e6d 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -657,8 +657,15 @@ failure classification, model discovery, admission, and commit-boundary retry.Neutral Anthropic-to-Responses input and Responses-to-Anthropic streamconversion remain in[core/openai_responses/](src/free_claude_code/core/openai_responses/), which-never imports OAuth, account IDs, or provider endpoints. The Admin API exposes-only safe connected-account state and never serializes token objects.+never imports OAuth, account IDs, or provider endpoints. That neutral converter+preserves the public Responses contract; the subscription provider owns the+private Codex request projection and omits fields that backend does not accept,+such as the public `max_output_tokens` cap and `metadata`. Successful private+responses can omit `Content-Type`, so the provider accepts an absent media type+for its always-streaming request and parses the body as SSE. An explicitly+declared non-SSE media type retains the bounded diagnostic failure path. The+Admin API exposes only safe connected-account state and never serializes token+objects.[providers/google_openai/](src/free_claude_code/providers/google_openai/) owns theGoogle-specific protocol behavior shared by AI Studio and Vertex AI: literaldiff --git a/pyproject.toml b/pyproject.tomlindex 2e62e3c7..5bc5dd4a 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "free-claude-code"-version = "4.16.4"+version = "4.16.5"description = "Local proxy connecting coding agents to OpenAI-compatible AI providers"readme = "README.md"requires-python = ">=3.14.0"diff --git a/src/free_claude_code/providers/openai_codex/provider.py b/src/free_claude_code/providers/openai_codex/provider.pyindex 1c44b1ad..53623cdc 100644--- a/src/free_claude_code/providers/openai_codex/provider.py+++ b/src/free_claude_code/providers/openai_codex/provider.py@@ -91,7 +91,7 @@ class OpenAICodexProvider(BaseProvider):*,reasoning: ReasoningPolicy = DEFAULT_REASONING_POLICY,) -> None:- """Validate lossless request conversion before any upstream I/O."""+ """Validate and adapt the private Codex request before upstream I/O."""self._build_body(request, reasoning=reasoning)@@ -152,9 +152,14 @@ class OpenAICodexProvider(BaseProvider):reasoning: ReasoningPolicy,) -> dict[str, Any]:try:- return build_responses_provider_request(request, reasoning=reasoning)+ body = build_responses_provider_request(request, reasoning=reasoning)except ResponsesConversionError as exc:raise InvalidRequestError(str(exc)) from exc+ # The private Codex backend rejects these public Responses fields.+ # Codex itself omits the output cap and uses separate internal metadata.+ body.pop("max_output_tokens", None)+ body.pop("metadata", None)+ return bodyasync def _run_stream(self,@@ -232,8 +237,8 @@ class OpenAICodexProvider(BaseProvider):truncated=body_truncated,)raise- content_type = response.headers.get("content-type", "")- if "text/event-stream" not in content_type.lower():+ content_type = response.headers.get("content-type")+ if content_type and "text/event-stream" not in content_type.lower():body_bytes, body_truncated = await _read_bounded_body(response)error = _TruncatedResponsesStream("OpenAI returned a non-streaming Responses payload."diff --git a/tests/api/test_openai_codex_compatibility.py b/tests/api/test_openai_codex_compatibility.pyindex e647f51f..30ed614b 100644--- a/tests/api/test_openai_codex_compatibility.py+++ b/tests/api/test_openai_codex_compatibility.py@@ -62,8 +62,7 @@ async def test_messages_accepts_current_claude_controls_for_openai_provider() ->upstream_requests.append(request)return httpx.Response(200,- text=_complete_stream("hello"),- headers={"content-type": "text/event-stream"},+ content=_complete_stream("hello").encode(),request=request,)@@ -101,6 +100,7 @@ async def test_messages_accepts_current_claude_controls_for_openai_provider() ->"model": "openai/gpt-test","max_tokens": 1024,"messages": [{"role": "user", "content": "hello"}],+ "metadata": {"user_id": "example-user"},"thinking": {"type": "adaptive", "display": "omitted"},"context_management": {"edits": [@@ -126,5 +126,7 @@ async def test_messages_accepts_current_claude_controls_for_openai_provider() ->payload = json.loads(upstream_requests[0].content)assert payload["model"] == "gpt-test"assert payload["reasoning"] == {"effort": "high", "summary": "auto"}+ assert "max_output_tokens" not in payload+ assert "metadata" not in payloadassert "context_management" not in payloadassert "output_config" not in payloaddiff --git a/tests/providers/test_openai_codex_provider.py b/tests/providers/test_openai_codex_provider.pyindex c4cd6618..30731434 100644--- a/tests/providers/test_openai_codex_provider.py+++ b/tests/providers/test_openai_codex_provider.py@@ -12,6 +12,7 @@ from free_claude_code.core.anthropic.stream_contracts import (parse_sse_text,text_content,)+from free_claude_code.core.diagnostics import ERROR_DETAIL_DISPLAY_CAP_BYTESfrom free_claude_code.core.failures import ExecutionFailurefrom free_claude_code.core.reasoning import ReasoningEffort, ReasoningPolicyfrom free_claude_code.providers.admission import ProviderAdmissionController@@ -77,6 +78,7 @@ def _client_control_request() -> MessagesRequest:"model": "gpt-test","max_tokens": 1024,"messages": [{"role": "user", "content": "hello"}],+ "metadata": {"user_id": "example-user"},"thinking": {"type": "adaptive", "display": "omitted"},"context_management": {"edits": [@@ -151,8 +153,7 @@ async def test_provider_uses_subscription_headers_and_visible_model_catalog() ->assert request.url.path.endswith("/responses")return httpx.Response(200,- text=_complete_stream("hello"),- headers={"content-type": "text/event-stream"},+ content=_complete_stream("hello").encode(),request=request,)@@ -215,6 +216,7 @@ async def test_provider_accepts_claude_client_controls_before_upstream_io() -> N_config(), auth=_FakeAuth(), admission=_admission(), client=client)request = _client_control_request()+ original_request = request.model_dump()reasoning = ReasoningPolicy.on(effort=ReasoningEffort.HIGH)provider.preflight_stream(request, reasoning=reasoning)@@ -235,8 +237,11 @@ async def test_provider_accepts_claude_client_controls_before_upstream_io() -> Npayload = json.loads(upstream.content)assert payload["model"] == "gpt-test"assert payload["reasoning"] == {"effort": "high", "summary": "auto"}+ assert "max_output_tokens" not in payload+ assert "metadata" not in payloadassert "context_management" not in payloadassert "output_config" not in payload+ assert request.model_dump() == original_requestassert_anthropic_stream_contract(parse_sse_text(body))await client.aclose()@@ -487,13 +492,20 @@ async def test_pre_stream_retry_discards_held_message_start() -> None:@pytest.mark.asyncioasync def test_non_streaming_success_is_retried_then_reports_bounded_body() -> None:attempts = 0+ tail_sentinel = "must-not-escape-the-diagnostic-cap"+ upstream_body = (+ "upstream contract changed\n"+ + "x" * ERROR_DETAIL_DISPLAY_CAP_BYTES+ + tail_sentinel+ ).encode()def handler(request: httpx.Request) -> httpx.Response:nonlocal attemptsattempts += 1return httpx.Response(200,- json={"error": {"message": "upstream contract changed"}},+ content=upstream_body,+ headers={"content-type": "application/json"},request=request,)@@ -516,6 +528,10 @@ async def test_non_streaming_success_is_retried_then_reports_bounded_body() -> Nassert attempts > 1assert "upstream contract changed" in exc_info.value.message+ assert f"truncated after {ERROR_DETAIL_DISPLAY_CAP_BYTES} bytes" in (+ exc_info.value.message+ )+ assert tail_sentinel not in exc_info.value.messageassert "Request ID: req_non_stream" in exc_info.value.messageawait client.aclose()diff --git a/uv.lock b/uv.lockindex abf1567f..ff0f7c54 100644--- a/uv.lock+++ b/uv.lock@@ -620,7 +620,7 @@ wheels = [[[package]]name = "free-claude-code"-version = "4.16.4"+version = "4.16.5"source = { editable = "." }dependencies = [{ name = "aiohttp" },