fix(embeddings): send explicit User-Agent on cloud HTTP requests#390
Open
kivo360 wants to merge 1 commit intotirth8205:mainfrom
Open
fix(embeddings): send explicit User-Agent on cloud HTTP requests#390kivo360 wants to merge 1 commit intotirth8205:mainfrom
kivo360 wants to merge 1 commit intotirth8205:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OpenAIEmbeddingProviderandMiniMaxEmbeddingProviderbuild their HTTP request through stdliburllib, which sends the defaultPython-urllib/3.xUser-Agent. Cloudflare-fronted gateways (notably Fireworks, a popular OpenAI-compatible backend) reject that signature with HTTP 403 / error 1010 ("browser signature banned"), surfacing as:…from
_call_api, which makesembed_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_AGENTconstant and sends it (plus an explicitAccept: 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_headerand an addition to the existingOpenAIEmbeddingProvider.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
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— cleanuv run pytest tests/test_embeddings.py -q— 85 passed (was 83, +2 new)embed_graphsmoke against Fireworksqwen3-embedding-8b— succeeds, returns 4096-dim vectorsNotes
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.