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
Recover from quoted output-token caps (#1362)
Ali Khokhar554c7d978779
diff --git a/pyproject.toml b/pyproject.tomlindex 5b63d43e..4c7e9b86 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "free-claude-code"-version = "4.17.3"+version = "4.17.4"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_chat/output_cap.py b/src/free_claude_code/providers/openai_chat/output_cap.pyindex 08cea7e7..cfdd4b5d 100644--- a/src/free_claude_code/providers/openai_chat/output_cap.py+++ b/src/free_claude_code/providers/openai_chat/output_cap.py@@ -24,14 +24,15 @@ _OUTPUT_TOKEN_FIELDS = ("max_completion_tokens", "max_tokens")_OUTPUT_TOKEN_KEYWORDS = ("max_completion_tokens", "max_tokens")# Comparator phrases that precede the allowed maximum in provider error text.+_CAP_VALUE_PATTERN = r"[`'\"]?(\d+)[`'\"]?"_CAP_PATTERNS: tuple[re.Pattern[str], ...] = (- re.compile(r"less than or equal to\s+(\d+)"),- re.compile(r"smaller than or equal to\s+(\d+)"),- re.compile(r"<=\s*(\d+)"),- re.compile(r"at most\s+(\d+)"),- re.compile(r"must not exceed\s+(\d+)"),- re.compile(r"maximum(?:\s+value)?(?:\s+for\s+\S+)?\s+is\s+(\d+)"),- re.compile(r"maximum(?:\s+allowed)?(?:\s+value)?\s+of\s+(\d+)"),+ re.compile(rf"less than or equal to\s+{_CAP_VALUE_PATTERN}"),+ re.compile(rf"smaller than or equal to\s+{_CAP_VALUE_PATTERN}"),+ re.compile(rf"<=\s*{_CAP_VALUE_PATTERN}"),+ re.compile(rf"at most\s+{_CAP_VALUE_PATTERN}"),+ re.compile(rf"must not exceed\s+{_CAP_VALUE_PATTERN}"),+ re.compile(rf"maximum(?:\s+value)?(?:\s+for\s+\S+)?\s+is\s+{_CAP_VALUE_PATTERN}"),+ re.compile(rf"maximum(?:\s+allowed)?(?:\s+value)?\s+of\s+{_CAP_VALUE_PATTERN}"),)diff --git a/tests/providers/test_openai_chat_output_cap.py b/tests/providers/test_openai_chat_output_cap.pyindex b9420dc9..e03d8235 100644--- a/tests/providers/test_openai_chat_output_cap.py+++ b/tests/providers/test_openai_chat_output_cap.py@@ -36,10 +36,11 @@ class _BadRequest(Exception):def test_parse_cap_from_groq_message():error = _BadRequest(- "max_completion_tokens must be less than or equal to 40960, the maximum "- "value for max_completion_tokens is less than the context_window for this model"+ "`max_completion_tokens` must be less than or equal to `16384`, the maximum "+ "value for `max_completion_tokens` is less than the `context_window` for this "+ "model")- assert parse_output_token_cap(error) == 40960+ assert parse_output_token_cap(error) == 16384@pytest.mark.parametrize(@@ -136,7 +137,18 @@ async def test_create_stream_clamps_and_learns_on_cap_rejection(groq_provider):assert body["max_completion_tokens"] == 64000model = body["model"]- error = _BadRequest("max_completion_tokens must be less than or equal to 40960")+ error = _BadRequest(+ "invalid request",+ body={+ "message": (+ "`max_completion_tokens` must be less than or equal to `16384`, "+ "the maximum value for `max_completion_tokens` is less than the "+ "`context_window` for this model"+ ),+ "type": "invalid_request_error",+ "param": "max_completion_tokens",+ },+ )create = AsyncMock(side_effect=[error, object()])with patch.object(groq_provider._client.chat.completions, "create", create):@@ -147,9 +159,9 @@ async def test_create_stream_clamps_and_learns_on_cap_rejection(groq_provider):await attempt.aclose()assert create.call_count == 2- assert create.call_args_list[1].kwargs["max_completion_tokens"] == 40960- assert used_body["max_completion_tokens"] == 40960- assert groq_provider._model_output_caps[model] == 40960+ assert create.call_args_list[1].kwargs["max_completion_tokens"] == 16384+ assert used_body["max_completion_tokens"] == 16384+ assert groq_provider._model_output_caps[model] == 16384@pytest.mark.asynciodiff --git a/uv.lock b/uv.lockindex 2b0c7939..3f6ccdeb 100644--- a/uv.lock+++ b/uv.lock@@ -620,7 +620,7 @@ wheels = [[[package]]name = "free-claude-code"-version = "4.17.3"+version = "4.17.4"source = { editable = "." }dependencies = [{ name = "aiohttp" },