Skip to content

fix(embeddings): send explicit User-Agent on cloud HTTP requests#390

Open
kivo360 wants to merge 1 commit intotirth8205:mainfrom
kivo360:fix/embedding-provider-user-agent
Open

fix(embeddings): send explicit User-Agent on cloud HTTP requests#390
kivo360 wants to merge 1 commit intotirth8205:mainfrom
kivo360:fix/embedding-provider-user-agent

Conversation

@kivo360
Copy link
Copy Markdown

@kivo360 kivo360 commented Apr 26, 2026

Summary

OpenAIEmbeddingProvider and MiniMaxEmbeddingProvider build their HTTP request through stdlib urllib, which sends the default Python-urllib/3.x User-Agent. Cloudflare-fronted gateways (notably Fireworks, a popular OpenAI-compatible backend) reject that signature with HTTP 403 / error 1010 ("browser signature banned"), surfacing as:

RuntimeError: OpenAI API HTTP 403: error code: 1010

…from _call_api, which makes embed_graph(provider=\"openai\") unusable against Fireworks out of the box even though the README explicitly lists "Qwen/Qwen3-Embedding-8B" (a Fireworks-hosted model) as a recommended choice.

This PR adds a single module-level _USER_AGENT constant and sends it (plus an explicit Accept: application/json) from both providers.

Changes

  • code_review_graph/embeddings.py: new _USER_AGENT = \"code-review-graph/<version> (+<repo URL>)\", threaded into both providers' headers.
  • tests/test_embeddings.py: two new assertions — MiniMaxEmbeddingProvider.test_embed_sends_user_agent_header and an addition to the existing OpenAIEmbeddingProvider.test_embed_calls_api_with_correct_payload — verifying the header is present on outgoing requests.

No public API change. Strict superset of existing behavior.

Reproducer

export CRG_OPENAI_API_KEY=fw_...
export CRG_OPENAI_BASE_URL=https://api.fireworks.ai/inference/v1
export CRG_OPENAI_MODEL=accounts/fireworks/models/qwen3-embedding-8b
export CRG_ACCEPT_CLOUD_EMBEDDINGS=1

# Before this PR:
python -c \"from code_review_graph.embeddings import get_provider; \
           get_provider('openai').embed_query('hi')\"
# RuntimeError: OpenAI API HTTP 403: error code: 1010

# After this PR:
# returns a 4096-dim vector

End-to-end: against a real omoi_os graph (11,572 nodes), `embed_graph(provider='openai')` against Fireworks Qwen3-Embedding-8B completes in ~3m45s after the fix; before the fix it errors on the first batch.

Test plan

  • uv run ruff check code_review_graph/embeddings.py tests/test_embeddings.py — clean
  • uv run pytest tests/test_embeddings.py -q — 85 passed (was 83, +2 new)
  • Live embed_graph smoke against Fireworks qwen3-embedding-8b — succeeds, returns 4096-dim vectors

Notes

  • I deliberately kept the UA narrow ("code-review-graph/ (+repo URL)") rather than impersonating a browser — gives upstream gateways a clean way to identify CRG traffic in their logs and reduces the chance of being clumped with bot fingerprints.
  • The same fix is plausibly relevant to any future provider that uses raw urllib (e.g. if a generic Cohere/Voyage provider is added later). Worth considering a tiny _call_with_user_agent(req) helper if more providers land.

Cloudflare-fronted gateways (e.g. Fireworks) reject the urllib default
"Python-urllib/X.Y" User-Agent with HTTP 403 / error 1010 ("browser
signature banned"), which surfaces as `OpenAI API HTTP 403: error code:
1010` from `OpenAIEmbeddingProvider._call_api` and breaks `embed_graph`
out of the box on those backends.

Add a single `_USER_AGENT` constant ("code-review-graph/<version>
(+repo URL)") and send it from both `MiniMaxEmbeddingProvider` and
`OpenAIEmbeddingProvider`, alongside an explicit `Accept` header. Also
adds unit tests asserting the header is present in outgoing requests
for both providers.

Reproducer (before the fix):

    export CRG_OPENAI_API_KEY=fw_...
    export CRG_OPENAI_BASE_URL=https://api.fireworks.ai/inference/v1
    export CRG_OPENAI_MODEL=accounts/fireworks/models/qwen3-embedding-8b
    export CRG_ACCEPT_CLOUD_EMBEDDINGS=1
    python -c "from code_review_graph.embeddings import get_provider; \
               get_provider('openai').embed_query('hi')"
    # RuntimeError: OpenAI API HTTP 403: error code: 1010

After the fix the same call returns a 4096-dim vector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant