feat(codex): enable image generation for all Codex upstream requests
Codex CLI gates the built-in image_generation tool behind
AuthMode::Chatgpt (OAuth only). When clients connect via API key
auth through CPA, the tool is absent from requests, making image
generation unavailable through the reverse proxy.
Changes:
1. Inject image_generation tool (codex_executor.go):
Add ensureImageGenerationTool() that appends
{"type":"image_generation","output_format":"png"} to the tools
array if not already present. Applied to all three execution
paths: Execute, executeCompact, and ExecuteStream.
2. Route aliases for Codex CLI direct access (server.go):
Add /backend-api/codex/responses routes that map to the same
OpenAI Responses API handlers as /v1/responses. This allows
Codex CLI to connect via chatgpt_base_url config while keeping
AuthMode::Chatgpt, which enables the built-in image_generation
tool on the client side.
3. Unit tests (codex_executor_imagegen_test.go):
Cover no-tools, existing tools, already-present, empty array,
and mixed built-in tool scenarios.
This commit is contained in:
@@ -353,6 +353,15 @@ func (s *Server) setupRoutes() {
|
||||
v1.POST("/responses/compact", openaiResponsesHandlers.Compact)
|
||||
}
|
||||
|
||||
// Codex CLI direct route aliases (chatgpt_base_url compatible)
|
||||
codexDirect := s.engine.Group("/backend-api/codex")
|
||||
codexDirect.Use(AuthMiddleware(s.accessManager))
|
||||
{
|
||||
codexDirect.GET("/responses", openaiResponsesHandlers.ResponsesWebsocket)
|
||||
codexDirect.POST("/responses", openaiResponsesHandlers.Responses)
|
||||
codexDirect.POST("/responses/compact", openaiResponsesHandlers.Compact)
|
||||
}
|
||||
|
||||
// Gemini compatible API routes
|
||||
v1beta := s.engine.Group("/v1beta")
|
||||
v1beta.Use(AuthMiddleware(s.accessManager))
|
||||
|
||||
Reference in New Issue
Block a user