feat(api): add Codex client models support for OpenAI API

- Introduced Codex client models framework in `openai` package.
- Added JSON-based model definitions (`codex_client_models.json`) for Codex, including metadata, reasoning levels, and configuration options.
- Implemented handlers to load, clone, and build Codex client models with support for visibility overrides and metadata application.
- Enabled sorting and prioritization of models based on configuration or runtime criteria.
- Added utility functions for managing and validating model attributes.
This commit is contained in:
Luis Pater
2026-05-17 04:48:34 +08:00
parent 53d1fd6c5c
commit 088ab33df8
7 changed files with 1092 additions and 1 deletions
@@ -8,6 +8,7 @@ package openai
import (
"context"
_ "embed"
"encoding/json"
"fmt"
"net/http"
@@ -29,6 +30,9 @@ type OpenAIAPIHandler struct {
*handlers.BaseAPIHandler
}
//go:embed codex_client_models.json
var codexClientModelsJSON []byte
// NewOpenAIAPIHandler creates a new OpenAI API handlers instance.
// It takes an BaseAPIHandler instance as input and returns an OpenAIAPIHandler.
//
@@ -59,6 +63,11 @@ func (h *OpenAIAPIHandler) Models() []map[string]any {
// It returns a list of available AI models with their capabilities
// and specifications in OpenAI-compatible format.
func (h *OpenAIAPIHandler) OpenAIModels(c *gin.Context) {
if _, ok := c.Request.URL.Query()["client_version"]; ok {
c.JSON(http.StatusOK, h.codexClientModelsResponse())
return
}
// Get all available models
allModels := h.Models()