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
Fix Auto Mode classifier responses when stream is omitted (#1098)
Ali Khokhar984c4c23b78d
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex ddfb4272..153abfc1 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -396,7 +396,8 @@ response. Once FCC has finalized the failure, the response includeswithout causing a second client retry loop. After the first chunk has escaped,HTTP status is committed; Messages emits an Anthropic `event: error` and closeswithout a synthetic `message_stop`; Responses emits `response.failed` with the-original response ID. Non-streaming Messages aggregate internally and return+original response ID. Messages are non-streaming unless the client explicitly+sets `stream: true`. Non-streaming Messages aggregate internally and returnnon-2xx JSON for any terminal stream error, discarding incomplete content ratherthan presenting a partial success.diff --git a/pyproject.toml b/pyproject.tomlindex 9d19ca7f..30db8792 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "free-claude-code"-version = "4.3.0"+version = "4.3.1"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/api/handlers/messages.py b/src/free_claude_code/api/handlers/messages.pyindex 36ea7e62..b5a86aeb 100644--- a/src/free_claude_code/api/handlers/messages.py+++ b/src/free_claude_code/api/handlers/messages.py@@ -135,12 +135,12 @@ class MessagesHandler:self,result: _MessagesResult,*,- stream: bool | None,+ stream: bool,request_id: str,) -> object:if isinstance(result, _MessagesCompleteResult):return result.response- if stream is False:+ if not stream:# Non-streaming clients (e.g. Claude Code utility calls) need a# complete JSON Message; the internal pipeline is always SSE, so# serving that raw here breaks the client SDK's response parse.diff --git a/src/free_claude_code/api/routes.py b/src/free_claude_code/api/routes.pyindex 2b045b9f..d88fbaba 100644--- a/src/free_claude_code/api/routes.py+++ b/src/free_claude_code/api/routes.py@@ -109,7 +109,7 @@ async def create_message(services: ApiServices = Depends(get_services),_auth=Depends(require_proxy_auth),):- """Create a message (streaming by default; stream=false gets aggregated JSON)."""+ """Create a message (JSON by default; stream=true returns Anthropic SSE)."""return await _create_messages_response(services,request_data,diff --git a/src/free_claude_code/core/anthropic/models.py b/src/free_claude_code/core/anthropic/models.pyindex 105c12a4..a0f639da 100644--- a/src/free_claude_code/core/anthropic/models.py+++ b/src/free_claude_code/core/anthropic/models.py@@ -183,7 +183,7 @@ class MessagesRequest(BaseModel):messages: list[Message]system: str | list[SystemContent] | None = Nonestop_sequences: list[str] | None = None- stream: bool | None = True+ stream: bool = Falsetemperature: float | None = Nonetop_p: float | None = Nonetop_k: int | None = Nonediff --git a/src/free_claude_code/core/anthropic/sse_aggregation.py b/src/free_claude_code/core/anthropic/sse_aggregation.pyindex 0827380c..9ddb336e 100644--- a/src/free_claude_code/core/anthropic/sse_aggregation.py+++ b/src/free_claude_code/core/anthropic/sse_aggregation.py@@ -1,10 +1,10 @@"""Fold an Anthropic Messages SSE stream into a single JSON Message body.-Used to honor client requests with ``stream: false``. The internal pipeline-is always SSE (provider execution always yields a stream), so-callers that need a non-streaming response consume the stream here and get-back the same shape the real Anthropic API returns for a non-streaming-``messages.create()`` call.+Used when client requests omit ``stream`` or set ``stream: false``. The internal+pipeline is always SSE (provider execution always yields a stream), so callers+that need a non-streaming response consume the stream here and get back the same+shape the real Anthropic API returns for a non-streaming ``messages.create()``+call."""import jsondiff --git a/tests/api/test_api.py b/tests/api/test_api.pyindex 482f0db3..6902d84a 100644--- a/tests/api/test_api.py+++ b/tests/api/test_api.py@@ -128,6 +128,36 @@ def test_create_message_stream(client: TestClient):assert _stream_response_calls[0][1]["request_id"] == response.headers["request-id"]+def test_auto_mode_classifier_without_stream_returns_json(client: TestClient):+ """Claude side queries omit stream and require one complete Message object."""+ _stream_response_calls.clear()+ payload = {+ "model": "claude-opus-4-8",+ "max_tokens": 64,+ "system": (+ "You are a security monitor. Respond with <block>yes</block> "+ "or <block>no</block>."+ ),+ "messages": [+ {+ "role": "user",+ "content": "<transcript>\nBash curl example.com\n</transcript>",+ }+ ],+ }++ response = client.post("/v1/messages?beta=true", json=payload)++ assert response.status_code == 200+ assert response.headers["content-type"].startswith("application/json")+ body = response.json()+ assert body["type"] == "message"+ assert body["usage"] == {"input_tokens": 0, "output_tokens": 0}+ routed_request = _stream_response_calls[0][0][0]+ assert routed_request.stream is False+ assert _stream_response_calls[0][1]["thinking_enabled"] is False++def test_create_message_ingress_error_has_request_id_without_terminal_header(client: TestClient,):diff --git a/tests/api/test_api_handlers.py b/tests/api/test_api_handlers.pyindex 4b636bce..8db13369 100644--- a/tests/api/test_api_handlers.py+++ b/tests/api/test_api_handlers.py@@ -103,6 +103,7 @@ async def test_messages_handler_passes_routed_request_and_stream_metadata() -> Nrequest = MessagesRequest(model="nvidia_nim/test-model",max_tokens=100,+ stream=True,messages=[Message(role="user", content="hi")],)@@ -373,6 +374,7 @@ async def test_messages_handler_forces_no_thinking_for_safety_classifier() -> Norequest = MessagesRequest(model="nvidia_nim/test-model",max_tokens=100,+ stream=True,system=_CLASSIFIER_SYSTEM,messages=[Message(role="user", content=_CLASSIFIER_USER)],)@@ -406,6 +408,7 @@ async def test_messages_handler_preserves_thinking_for_non_classifier() -> None:request = MessagesRequest(model="nvidia_nim/test-model",max_tokens=100,+ stream=True,system="Explain XML formats.",messages=[Message(@@ -441,6 +444,7 @@ async def test_messages_handler_keeps_existing_no_thinking_for_classifier() -> Nrequest = MessagesRequest(model="claude-3-freecc-no-thinking/nvidia_nim/test-model",max_tokens=100,+ stream=True,system=_CLASSIFIER_SYSTEM,messages=[Message(role="user", content=_CLASSIFIER_USER)],)diff --git a/tests/api/test_web_server_tools.py b/tests/api/test_web_server_tools.pyindex d6604400..8e93f84c 100644--- a/tests/api/test_web_server_tools.py+++ b/tests/api/test_web_server_tools.py@@ -424,6 +424,7 @@ async def test_service_streams_forced_web_search_by_default(monkeypatch):request = MessagesRequest(model="claude-haiku-4-5-20251001",max_tokens=100,+ stream=True,messages=[Message(role="user", content="Search for DeepSeek V4")],tools=[Tool(name="web_search", type="web_search_20250305")],tool_choice={"type": "tool", "name": "web_search"},diff --git a/tests/core/anthropic/test_models.py b/tests/core/anthropic/test_models.pyindex 10ff809c..01e26751 100644--- a/tests/core/anthropic/test_models.py+++ b/tests/core/anthropic/test_models.py@@ -1,4 +1,5 @@import pytest+from pydantic import ValidationErrorfrom free_claude_code.core.anthropic.conversion import (OpenAIConversionError,@@ -21,6 +22,19 @@ def test_messages_request_parses_without_model_mapping_side_effects():)assert request.model == "claude-3-opus"+ assert request.stream is False+++def test_messages_request_rejects_null_stream() -> None:+ with pytest.raises(ValidationError):+ MessagesRequest.model_validate(+ {+ "model": "claude-3-opus",+ "max_tokens": 100,+ "messages": [{"role": "user", "content": "hello"}],+ "stream": None,+ }+ )def test_messages_request_normalizes_system_role_messages():@@ -292,7 +306,7 @@ def test_messages_request_dump_preserves_public_defaults_and_excludes_internal_fassert dumped == {"model": "model","messages": [{"role": "user", "content": "hello"}],- "stream": True,+ "stream": False,"thinking": {"enabled": True, "type": "adaptive"},"client_extension": {"enabled": True},}diff --git a/uv.lock b/uv.lockindex 9d385036..15793dc5 100644--- a/uv.lock+++ b/uv.lock@@ -561,7 +561,7 @@ wheels = [[[package]]name = "free-claude-code"-version = "4.3.0"+version = "4.3.1"source = { editable = "." }dependencies = [{ name = "aiohttp" },