Skip to content

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: normalize proxy auth token whitespace

Alishahryar1c1af215ff748
diff --git a/api/dependencies.py b/api/dependencies.py
index fbc37b08..cb796b05 100644
--- a/api/dependencies.py
+++ b/api/dependencies.py
@@ -96,7 +96,7 @@ def require_api_key(
Checks `x-api-key` header or `Authorization: Bearer ...` against
`Settings.anthropic_auth_token`. If `ANTHROPIC_AUTH_TOKEN` is empty, this is a no-op.
"""
- anthropic_auth_token = settings.anthropic_auth_token
+ anthropic_auth_token = settings.anthropic_auth_token.strip()
if not anthropic_auth_token:
# No API key configured -> allow
return
@@ -110,13 +110,13 @@ def require_api_key(
raise HTTPException(status_code=401, detail="Missing API key")
# Support both raw key in X-API-Key and Bearer token in Authorization
- token = header
+ token = header.strip()
if header.lower().startswith("bearer "):
- token = header.split(" ", 1)[1]
+ token = header.split(" ", 1)[1].strip()
# Strip anything after the first colon to handle tokens with appended model names
if token and ":" in token:
- token = token.split(":", 1)[0]
+ token = token.split(":", 1)[0].strip()
# Constant-time comparison to avoid leaking the configured token via
# response-time differences on a per-byte mismatch (CWE-208).
diff --git a/pyproject.toml b/pyproject.toml
index cde57a8f..c5e9428f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "free-claude-code"
-version = "1.2.40"
+version = "1.2.41"
description = "Middleware between Claude Code CLI (Anthropic API) and NVIDIA NIM"
readme = "README.md"
requires-python = ">=3.14.0"
diff --git a/tests/api/test_auth.py b/tests/api/test_auth.py
index 57ba066a..2e140f50 100644
--- a/tests/api/test_auth.py
+++ b/tests/api/test_auth.py
@@ -59,6 +59,29 @@ def test_anthropic_auth_token_accepts_bearer_authorization():
app.dependency_overrides.clear()
+def test_anthropic_auth_token_normalizes_configured_whitespace():
+ client = TestClient(app)
+ settings = Settings()
+ settings.anthropic_auth_token = " spaced-token \n"
+ app.dependency_overrides[get_settings] = lambda: settings
+
+ payload = {
+ "model": "claude-3-sonnet",
+ "messages": [{"role": "user", "content": "hello"}],
+ }
+
+ with patch("api.routes.get_token_count", return_value=3):
+ r = client.post(
+ "/v1/messages/count_tokens",
+ json=payload,
+ headers={"Authorization": "Bearer spaced-token"},
+ )
+ assert r.status_code == 200
+ assert r.json()["input_tokens"] == 3
+
+ app.dependency_overrides.clear()
+
+
def test_anthropic_auth_token_applies_to_models_endpoint():
client = TestClient(app)
settings = Settings()
diff --git a/uv.lock b/uv.lock
index fd43800b..a8c34978 100644
--- a/uv.lock
+++ b/uv.lock
@@ -554,7 +554,7 @@ wheels = [
[[package]]
name = "free-claude-code"
-version = "1.2.40"
+version = "1.2.41"
source = { editable = "." }
dependencies = [
{ name = "aiohttp" },