refactor: standardize OpenAI API routes to use /v1/ prefix - #36
Conversation
|
Hey, thanks for the PR. Looks like the only real value is consistency with the OpenAI API. Integrating with client libraries is already possible and we have a Python SDK example on the homepage. So I get the value, but I don't think there's enough ROI to be breaking backwards compatibility here. Or is there a particular popular SDK that can't work with the URLs we have here? Can you provide more details if so please? Cheers! |
|
Thanks for the feedback! You'''re right that SDKs work fine with custom base URLs. However, I'''ve identified a more practical compatibility issue: API gateways and aggregation services. Many organizations use API gateways and AI service aggregators that have hardcoded routing logic expecting the standard
These systems often can'''t easily adapt to non-standard paths without manual configuration changes, which creates real integration friction. That said, I understand the backwards compatibility concern. Would you consider this for a future major version (v2.0) when other breaking changes are planned? Or I'''m happy to close this PR for now and revisit later. What do you think? |
|
Understood. Thanks for keeping it concise. I don't ever intend to do a v2 if I can help it. But what we can do is to support those I also just noticed that we haven't documented support for Anthropic messages API, which does have Does that make sense? Agree? Can you implement it that way in your PR please? |
|
Perfect! That'''s a much better approach. I'''ve implemented exactly what you suggested: Changes Made✅ Added dual path support:
✅ Updated code:
✅ Added comprehensive tests:
✅ Documentation:
Benefits
The PR is ready for review. Thanks for the excellent suggestion! |
✅ Tests Complete! All Passing!I've implemented and tested according to your suggestion: 🧪 Test Results
🔧 Implementation
🎯 Benefits
PR is ready for review! Thanks for the excellent suggestion—this is definitely a better approach than a complete replacement. |
sharat87
left a comment
There was a problem hiding this comment.
Hey, sorry, I've already documented the Anthropic messages etc., but forgot to push. Can you resolve conflicts and only make the minimal changes needed on top of this please?
- Update OpenAI completion endpoints from /llm/completions to /llm/v1/completions - Update chat completion endpoints from /llm/chat/completions to /llm/v1/chat/completions - Update response endpoints from /llm/responses to /llm/v1/responses - Update corresponding tests and documentation
- Add support for both /llm/v1/ and /llm/ paths for all OpenAI endpoints - Keep legacy paths (without /v1/) for backward compatibility - Add comprehensive tests for both path variants - Documentation already uses /v1/ paths as the standard - No breaking changes - existing integrations continue to work
a8f5eb5 to
bc825bb
Compare
done |
There was a problem hiding this comment.
Pull request overview
This PR standardizes httpbun’s OpenAI-mock routes to include an /llm/v1/ prefix (matching OpenAI’s conventional /v1 API structure), while preserving the legacy non-/v1 endpoints for backward compatibility. It also updates the Python SDK integration tests and the HTML documentation to reflect the new standard paths.
Changes:
- Added
/llm/v1/*OpenAI routes alongside legacy/llm/*routes. - Updated OpenAI/Responses/Anthropic SDK tests to use SDK-specific base URL fixtures and added explicit “v1 path” + backward-compat tests.
- Updated the frontend documentation to show the new
/llm/v1/...endpoints and the OpenAI SDK base URL.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| routes/llm/openai.go | Registers new /llm/v1/... routes while keeping legacy endpoints for compatibility. |
| llm-sdk-tests/tests/test_openai.py | Switches to openai_base_url and adds tests for v1 + backward-compatible paths. |
| llm-sdk-tests/tests/test_openai_responses.py | Switches to openai_base_url and adds tests for v1 + backward-compatible paths (Responses API). |
| llm-sdk-tests/tests/test_anthropic.py | Switches to anthropic_base_url and adds additional path-compat tests. |
| llm-sdk-tests/tests/conftest.py | Adds base URL helpers/fixtures to provide correct base URLs per SDK. |
| assets/index.html | Updates documented endpoints and examples to use /llm/v1/... and /llm/v1 for OpenAI SDK. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def _get_base_url(suffix: str = "") -> str: | ||
| """Get base URL from environment, with optional suffix for SDK-specific paths.""" | ||
| base = os.getenv("BASE_URL", "http://localhost:3090") | ||
| if suffix and not base.endswith(suffix): | ||
| return base + suffix | ||
| return base |
Summary
This PR standardizes the OpenAI API routes to follow the official OpenAI API convention by adding the '/v1/' prefix to all endpoints.
Changes
API Routes Updated:
Test Updates: Updated all related test files to use the new endpoint paths
Documentation: Updated API documentation in the frontend
Rationale
This change brings the API routes in line with OpenAI's standard API path structure, making:
Testing
All existing tests have been updated to use the new endpoint paths and pass successfully.