Skip to content

fix(api): for /backend-api/codex/model, return it in codex format#331

Merged
Soju06 merged 2 commits intoSoju06:mainfrom
huzky-v:fix/upstream-codex-api
Apr 6, 2026
Merged

fix(api): for /backend-api/codex/model, return it in codex format#331
Soju06 merged 2 commits intoSoju06:mainfrom
huzky-v:fix/upstream-codex-api

Conversation

@huzky-v
Copy link
Copy Markdown
Collaborator

@huzky-v huzky-v commented Apr 5, 2026

Address part of #324 , Updating /backend-api/codex/models API to a format that at least codex-cli accepts

Although that the codex-cli behavior cannot be changed this moment, and the change of /backend-api/codex/models does not affect the codex-cli /model because of the codex mechanism

It is always good to align the format with the upstream and prepare it when codex is compatible with that one day.

Tested on my modified codex-cli with success.

@huzky-v huzky-v force-pushed the fix/upstream-codex-api branch 4 times, most recently from cb30c95 to 5a6c965 Compare April 5, 2026 06:15
@alexjx
Copy link
Copy Markdown

alexjx commented Apr 5, 2026

Thank you very much! Align this is very beneficial. I'm looking for a way to manually override the model cache before running the real codex, This way we can align the /model command benhavior.

@huzky-v
Copy link
Copy Markdown
Collaborator Author

huzky-v commented Apr 5, 2026

Oh it could be done by some simple shell script and aliasing.

Something like this will do

#!/usr/bin/env bash
set -euo pipefail

CLIENT_VERSION=$(codex --version | sed 's/^codex-cli //')

MODELS_RESPONSE=$(curl -s -H "Authorization: Bearer ${ENV_KEY}" https://your.codex-lb.location/backend-api/codex/models -o test.json)

jq -n \
  --arg fetched_at "2099-12-31T23:59:59.000000Z" \
  --arg client_version "$CLIENT_VERSION" \
  --argjson models "$(cat test.json | jq '.models')" \
  '{fetched_at: $fetched_at, client_version: $client_version, models: $models}' \
  > ~/.codex/models_cache.json

rm test.json
exec codex "$@"

and do an alias to codex.

Although the allowed model selection in codex-lb will not exactly equal to the output of /model, which still constrained by some kind of the codex-cli default list, which has 6 of them
And it still hide something that exists in models_cache.json

EDIT: just found that you can control visibility to hide or list to control the output of /model, and I can now control what to show on /model by allowing specific model in api dashboard
螢幕截圖 2026-04-05 22 32 21

@huzky-v huzky-v force-pushed the fix/upstream-codex-api branch from 5a6c965 to b9edf65 Compare April 5, 2026 08:27
@alexjx
Copy link
Copy Markdown

alexjx commented Apr 5, 2026

I have a simpler configuration to do that, with digging into codex source code, there is an option --config "model_catalog_json=<path to a file contains codex models dump>", which we can use the codex model format as file. So we don't need to convert, just dumping the response directly to the file.

@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented Apr 6, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b9edf65404

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/api.py Outdated
Comment thread app/modules/proxy/api.py
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented Apr 6, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented Apr 6, 2026

Thank you for your contribution!

@Soju06 Soju06 merged commit c141a8a into Soju06:main Apr 6, 2026
15 checks passed
@huzky-v huzky-v deleted the fix/upstream-codex-api branch April 6, 2026 02:33
Copy link
Copy Markdown
Collaborator Author

@huzky-v huzky-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just filtering out the list on /backend-api/codex/models for API Allowed Model is not enough for codex-cli as it has a default visibility value for various model. You need to explicitly set it to hide in the response so that the /models will not show the model

Filtering may not align the /v1/models behavior to just let the app to show the models available to the API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants