Repository navigation
Labels
scope/aiAI review pipeline, personas, prompts, LLM client, or RAGsource/agentFiled by an agenttype/bugType bug: the code does not do what it must
Description
Problem
Checked at release/v0.2.29 (05e9388).
OpenAICompatProviderMixin._api_basereturnsCONST_URL_OPENAI_API_BASE, which ishttps://api.openai.com(config/constants.py:590,ai/client/openai.py:46). The client appends/chat/completionsand/models(openai.py:169,:199,:217). The OpenAI API serves those routes under/v1, so provideropenaiwithoutai.api_base_urlsends every chat, stream and model listing to a route that does not exist.- Three other defaults include
/v1:ai/providers/openai.py:41,ai/rag/embeddings.py:889and the review dry-run preview (ai/review/runner.py:210). The preview and the embeddings therefore show a URL that chat never uses. - The cause is that the whole request is assembled by hand: the URL, the bearer header (
openai.py:48-54), the payload (:81-105), the response parse (:120-153), the SSE event decoding (ai/client/streaming.py:350-385) and the error mapping by status (ai/client/base.py:119-132). - The
openaiSDK (OpenAI; 3.26.1, released 2026-10-08; 3.13.0 is already in uv.lock through pydantic-ai) defaults tohttps://api.openai.com/v1and accepts anhttpx2.Clientashttp_client. The factory's egress-checked client (http/client.py:142) can therefore stay the transport, so fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898's connect-time check and the HTTP-edge test fakes keep working.
Proposed remedy
OpenAICompatProviderMixinholds oneopenai.OpenAI(base_url=..., api_key=..., http_client=<the provider's factory client>, max_retries=0, timeout=<the client's request timeout>)per client. Chat (chat.completions.create, withstream=Truefor streams) and model listing (models.list) go through it. Provideropenaitakes the SDK's default base URL;copilotandgatewaykeep their configured base URLs.- The gateway's served-by header is read from the raw response (
with_raw_response, or the stream's response headers). openai.APIStatusErrorandopenai.APIConnectionErrormap toAIClientErrorandcredentials_errorby exception type and status, not by text.- Reasoning text (
reasoning_contentorreasoningin a delta) is read from the SDK chunk's extra fields. - Delete
CONST_URL_OPENAI_API_BASE, the other hand-written OpenAI defaults,_build_compat_payload,_parse_compat_response,_openai_compat_headersand_openai_stream_frame. - Declare
openaiinpyproject.toml. - Unchanged: Ollama slot leasing and request priority (
ai/client/network.py), feat(ai): finish reasons and stream completeness for model replies #599's finish reasons and fix(ai): sampling settings reach the model or are refused, review sessions record them, and the reply cache key includes them #1070's sampling rules.
Key questions
- How is the response-size cap kept?
request_limited_json(ai/client/network.py:324) reads at mostDEFAULT_AI_MAX_RESPONSE_BYTES, and the SDK reads the whole body. (proposed) Call throughwith_streaming_response, read at most the cap, then validate the bytes into the SDK'sChatCompletionmodel. - Who retries? (proposed) Only the factory's tenacity transport (
new_http_client(retries=...),http/client.py:163-166), with the SDK'smax_retries=0, so retries do not multiply and fix(ai): the spend ledger records every attempt the gateway failed, including the retry transport's, and its gap to the gateway's count is measured first #1019's attempt accounting holds.
Acceptance criteria
- With provider
openaiand noai.api_base_url, the recorded requests go tohttps://api.openai.com/v1/chat/completions(unstreamed and streamed) andhttps://api.openai.com/v1/models. The test fails on the current code. - With provider
copilot, and with providergatewayandai.gateway_url: https://example.com/v1, the recorded URLs are the configured base plus/chat/completions, as today. - The SDK client's HTTP client is the one the factory built (an identity check), so the egress check covers every request it sends.
- The existing finish-reason, stream-completeness and served-by tests pass against SDK-built requests.
-
rg -n 'api.openai.com' srcprints no hand-written default, andrg -n '_openai_stream_frame|_build_compat_payload|_parse_compat_response' srcprints nothing. - Tests run offline, with fakes only at the HTTP edge (an httpx2
MockTransport, throughtests/llm_stream_fakes.route_clientor refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's fixture) or the process edge. No test patches a devops_cli name. - Each new or changed test runs in under 1 s.
-
uv run devops cipasses.
Related: #1001 (moves this client behind its factory), #888, #1070, #591, #1419, #1019
Found by the 2026-10-08 client-library audit.
Opened as a borrow (#1153, budget/borrowed): the agent filing quota is spent for this cycle, and this is a defect or security finding of the owner-requested 2026-10-08 client-library audit.
Update 2026-10-08: remedy follows the owner's #1001 decision
#1001 now uses pydantic-ai models, not the openai SDK directly, so this item's remedy changes:
- The
openaiprovider is a pydantic-aiOpenAIChatModeloverOpenAIProvider, built withhttp_client=from the egress factory. It is called throughpydantic_ai.direct.model_request_syncandmodel_request_stream_sync. - With no
ai.api_base_url, the provider's own default (https://api.openai.com/v1) applies. The hand-written defaults and builders listed above are deleted as planned. - The acceptance criteria stand: the recorded requests go to
/v1/chat/completionsand/v1/models, and the client is the factory-built one (an identity check on the provider's client).
If #1001 lands first, this item is its OpenAI step. Otherwise it lands this provider as #1001's first step.
Metadata
Metadata
Assignees
Labels
scope/aiAI review pipeline, personas, prompts, LLM client, or RAGsource/agentFiled by an agenttype/bugType bug: the code does not do what it must
Type
Projects
- StatusShow more project fieldsIn Review
Activity
dan-petty-bot commentedon Oct 8, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
The default OpenAI provider is completely broken for any user who does not set ai.api_base_url, affecting every chat, stream, and model-listing call.The fix requires replacing hand-written HTTP, streaming, error-mapping, and payload code with the openai SDK while preserving egress checks, retry accounting, response-size caps, and existing test contracts.fix(ai): the openai provider without ai.api_base_url calls the OpenAI…
chore(main): release 0.6.2 (#2287)