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(gemini): strip unsupported metadata key from requests (#1552)
Manish Tiwari6b3f16f41d4b
diff --git a/pyproject.toml b/pyproject.tomlindex 8566519c..207a18c7 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "free-claude-code"-version = "5.14.6"+version = "5.14.7"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/gemini/client.py b/src/free_claude_code/providers/gemini/client.pyindex 1dee808d..fca817c3 100644--- a/src/free_claude_code/providers/gemini/client.py+++ b/src/free_claude_code/providers/gemini/client.py@@ -18,6 +18,10 @@ _REQUEST_POLICY = OpenAIChatRequestPolicy(reasoning_replay=ReasoningReplayMode.REASONING_CONTENT,include_extra_body=True,extra_body_validator=validate_google_extra_body,+ # Google's OpenAI-compatible endpoint rejects the whole request with+ # "Unknown name 'metadata': Cannot find field" if this key is present,+ # whether at the top level or inside a caller-supplied extra_body (#1548).+ unsupported_body_keys=frozenset({"metadata"}),)_PROFILE = OpenAIChatProfile(_REQUEST_POLICY,diff --git a/src/free_claude_code/providers/openai_chat/request_policy.py b/src/free_claude_code/providers/openai_chat/request_policy.pyindex 2d15a395..5cf584df 100644--- a/src/free_claude_code/providers/openai_chat/request_policy.py+++ b/src/free_claude_code/providers/openai_chat/request_policy.py@@ -155,6 +155,15 @@ def _apply_common_openai_chat_policy(for key in policy.unsupported_body_keys:body.pop(key, None)+ # unsupported_body_keys must also be stripped from a caller-supplied+ # extra_body: it becomes the SDK's own extra_body= kwarg and gets merged+ # into the wire-level JSON verbatim, so a key unsupported at the top+ # level is equally unsupported when it arrives this way (#1548).+ extra_body = body.get("extra_body")+ if isinstance(extra_body, dict):+ for key in policy.unsupported_body_keys:+ extra_body.pop(key, None)+if policy.max_tokens_field == "max_completion_tokens":_normalize_max_completion_tokens(body)diff --git a/tests/providers/test_gemini.py b/tests/providers/test_gemini.pyindex 2cc88ea5..448a38c8 100644--- a/tests/providers/test_gemini.py+++ b/tests/providers/test_gemini.py@@ -199,25 +199,42 @@ def test_gemini_adaptive_thinking_with_effort_does_not_emit_custom_config(def test_build_request_body_preserves_caller_extra_body(gemini_provider):- req = make_request(extra_body={"metadata": {"user": "u1"}})+ # This opaque sentinel verifies FCC's pass-through contract only; it does not+ # imply that Gemini accepts an undocumented "custom_tag" wire field.+ req = make_request(extra_body={"custom_tag": {"user": "u1"}})body = gemini_provider._build_request_body(req, reasoning=reasoning_for(req))assert "reasoning_effort" not in bodyeb = body.get("extra_body")assert isinstance(eb, dict)- assert eb.get("metadata") == {"user": "u1"}+ assert eb.get("custom_tag") == {"user": "u1"}literal_extra_body = eb.get("extra_body")assert isinstance(literal_extra_body, dict)google = literal_extra_body.get("google")assert isinstance(google, dict)+def test_build_request_body_strips_unsupported_metadata_key(gemini_provider):+ """Regression for #1548: Gemini's OpenAI-compat endpoint hard-rejects the+ whole request with "Unknown name 'metadata': Cannot find field" if this+ key is present -- whether the caller sends it as a top-level extra_body+ entry or FCC would otherwise forward it verbatim via the SDK merge.+ """+ req = make_request(extra_body={"metadata": {"user_id": "u1"}})++ body = gemini_provider._build_request_body(req, reasoning=reasoning_for(req))+ wire_json = _simulate_openai_sdk_wire_json(body)++ assert "metadata" not in body+ assert "metadata" not in body.get("extra_body", {})+ assert "metadata" not in wire_json++def test_build_request_body_merges_caller_nested_google(gemini_provider):req = make_request(thinking=None,extra_body={- "metadata": {"user": "u1"},"extra_body": {"google": {"thinking_config": {@@ -235,7 +252,6 @@ def test_build_request_body_merges_caller_nested_google(gemini_provider):assert "reasoning_effort" not in bodyeb = body.get("extra_body")assert isinstance(eb, dict)- assert eb.get("metadata") == {"user": "u1"}literal_extra_body = eb.get("extra_body")assert isinstance(literal_extra_body, dict)google = literal_extra_body.get("google")diff --git a/uv.lock b/uv.lockindex d768b367..a965f94a 100644--- a/uv.lock+++ b/uv.lock@@ -607,7 +607,7 @@ wheels = [[[package]]name = "free-claude-code"-version = "5.14.6"+version = "5.14.7"source = { editable = "." }dependencies = [{ name = "aiohttp" },