Repository navigation
feat(api): implement GET /v1/models/{model} retrieve model endpoint - #46
Merged
Mag1cFall merged 1 commit intoOct 4, 2026
Merged
Conversation
- Register GET /v1/models/{model...} route to support retrieving single model details
- Support model lookup by canonical ID, 'models/' prefix, and configured aliases
- Return Anthropic model object when Anthropic-Version header is present
- Return standard 404 model_not_found error when model does not exist
- Add comprehensive unit tests in internal/api/models_test.go
- Update API endpoint documentation in README and docs
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.
Description
Summary
Implements the
GET /v1/models/{model}endpoint for retrieving individual model metadata, adhering to the OpenAI Models API specification (client.models.retrieve(...)).Previously, only
GET /v1/models(listing all models) andGET /v1beta/models/{model}(Gemini single-model route) were available. Standard OpenAI SDKs and third-party tools queryingGET /v1/models/{model}received a404 Not Foundresponse.Key Changes
Routing (
internal/api/router.go):GET /v1/models/{model...}in the publichttp.ServeMux.{model...}wildcard pattern to accommodate both plain model IDs (gemini-2.5-flash) and prefixed/namespaced identifiers (models/gemini-2.5-flash).OpenAI Model Handler (
internal/api/openai.go):openAIModelObject(model aistudio.Model) map[string]anyhelper to ensure shared schema consistency between model list and retrieve endpoints.handleOpenAIModel(w http.ResponseWriter, r *http.Request):models/prefix, and configured aliases (capability_options.aliases).object: "model", limits, methods, capabilities, paid flags).404 Not Foundwith standardized OpenAI error structure (code: "model_not_found",type: "invalid_request_error") if the requested model does not exist.Anthropic Compatibility (
internal/api/anthropic.go):writeAnthropicModel(w http.ResponseWriter, model aistudio.Model).Anthropic-Versionheader, returns Anthropic-formatted model objects (type: "model"), ornot_found_erroron 404.Unit Tests (
internal/api/models_test.go):TestOpenAIModelsEndpointcovering:list models openai: verifyingGET /v1/modelsformat.list models anthropic: verifyingGET /v1/modelswithAnthropic-Version.retrieve model by id: verifyingGET /v1/models/gemini-2.5-flash.retrieve model with prefix models/: verifyingGET /v1/models/models/gemini-2.5-flash.retrieve model by alias: verifying lookup via alias configured incapability_options.aliases.retrieve model not found: validating 404 status andmodel_not_founderror payload.retrieve model anthropic found: validating Anthropic response structure.retrieve model anthropic not found: validating 404 Anthropicnot_found_error.Documentation:
README.md,README_en.md,docs/protocol.md, anddocs/development.md.Verification
go test -v ./internal/api -run TestOpenAIModelsEndpoint: all subtests passed.go test ./...: all package tests across repository passed.go vet ./...: 0 warnings or errors.