Reject /v1 suffix on OpenAIProvider base_url#84
Merged
chris-colinsky merged 2 commits intoMay 28, 2026
Conversation
httpx joins base_url paths by appending, so an unprefixed /v1 on base_url produces a doubled /v1/v1/... wire path that some backends (Bifrost was the motivating case) accept on GET /v1/v1/models while rejecting POST /v1/v1/chat/completions. Result: the readiness probe stays green and every completion silently 405s. Raise ValueError at construction time when base_url's path ends in /v1 (with or without trailing slash) so the misconfiguration is visible at lifespan startup, not inside per-call wire failures. Trailing slashes are still normalized; other non-empty paths (proxy prefixes like /api/openai-proxy) are left alone for intentional reverse-proxy setups. Also fix docs/model-providers/index.md which wrongly showed base_url="http://localhost:8000/v1" as the canonical shape.
There was a problem hiding this comment.
Pull request overview
This PR tightens OpenAIProvider configuration by rejecting base_url values that would cause duplicated /v1 paths when the provider appends its own OpenAI-compatible endpoints.
Changes:
- Adds
base_urlvalidation and normalization inOpenAIProvider. - Documents the required host-root
base_urlshape. - Adds unit tests for accepted and rejected
base_urlforms.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/openarmature/llm/providers/openai.py |
Adds validation helper, constructor integration, and provider docstring guidance. |
tests/unit/test_llm_provider.py |
Adds unit coverage for /v1 rejection and accepted proxy/root URL cases. |
docs/model-providers/index.md |
Updates the example provider configuration to use host root only. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The previous validation called rstrip("/") on the full base_url
before parsing, which is a no-op when the URL ends in a query
string or fragment character (e.g., the 'c' in '?token=abc').
The parsed path's own trailing slash was then left intact, so
'/v1/' slipped past the endswith('/v1') check.
Strip trailing slashes from the parsed path itself before the
suffix check. Adds two unit tests covering the query-string and
fragment cases.
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
Reject
base_urlvalues whose path ends in/v1(with or without a trailing slash) atOpenAIProviderconstruction time. httpx joins base URLs by appending the request path, so abase_urllikehttps://api.openai.com/v1plus the provider's/v1/chat/completionsrequest produces a doubled/v1/v1/chat/completionson the wire. Some backends (Bifrost was the motivating case from a downstream consumer) return 200 forGET /v1/v1/modelsbut rejectPOST /v1/v1/chat/completions— the readiness probe goes green at lifespan startup and every completion silently 405s.Strict
ValueErrorrather than silent strip-and-warn keeps the misconfiguration visible at construction. Other non-empty paths (proxy prefixes like/api/openai-proxyor/v1/openai-proxy) are left alone for intentional reverse-proxy setups; only a trailing/v1is rejected.Behavior
base_urlhttps://api.openai.comhttp://localhost:8090/https://api.openai.com/v1ValueErrorhttp://localhost:8090/v1/ValueErrorhttps://gateway.example.com/openai-proxy/v1path)https://gateway.example.com/v1/openai-proxy/v1not trailing)Test plan
tests/unit/test_llm_provider.pycover each caseruff check/ruff format --checkcleanpyrightclean on changed filesdocs/model-providers/index.mdfixed (was showing the rejected/v1shape as canonical)