Skip to content

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

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

Soju06 merged 2 commits into
Soju06:mainfrom
huzky-v:fix/upstream-codex-api

Conversation

@huzky-v

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

Copy link
Copy Markdown
Collaborator

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

alexjx commented Apr 5, 2026

Copy link
Copy Markdown

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

huzky-v commented Apr 5, 2026 •

Copy link
Copy Markdown
Collaborator Author

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

alexjx commented Apr 5, 2026

Copy link
Copy Markdown

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

Soju06 commented Apr 6, 2026

Copy link
Copy Markdown
Owner

@codex review

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

Copy link
Copy Markdown

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 Resolved
Comment thread app/modules/proxy/api.py Resolved
@Soju06

Soju06 commented Apr 6, 2026

Copy link
Copy Markdown
Owner

@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

Soju06 commented Apr 6, 2026

Copy link
Copy Markdown
Owner

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

@huzky-v huzky-v left a comment •

Copy link
Copy Markdown
Collaborator Author

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

Soju06 added a commit that referenced this pull request Jul 10, 2026
* fix(proxy): preserve model_messages in catalog response

codex-lb stripped `model_messages` from upstream model entries via
`_FILTERED_FIELDS` in model_fetcher.py. The Codex client's model picker
needs this field to display newer models (gpt-5.6-sol/terra/luna);
without it the client silently drops models absent from its bundled
metadata. PR #331 removed `base_instructions` from the filter for the
same reason — `model_messages` was left behind by oversight.

Remove the dead `_FILTERED_FIELDS` abstraction and use `raw = dict(data)`
to preserve all upstream fields verbatim, making the catalog response
field-for-field identical to the upstream ChatGPT backend response.

Adds regression tests at the fetcher boundary and the catalog endpoint,
plus an OpenSpec change folder.

* chore(pr): finalize preserve-model-messages-in-catalog for merge

- Merge origin/main into the PR branch.
- Add zepx (Choong Jun Jin) to .all-contributorsrc (code, test).
- Check off completed tasks in the OpenSpec change tasks.md.
- Add a direct client_version-path regression test asserting
  GET /v1/models?client_version=<v> preserves model_messages for a
  live-catalog model.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Soju06 <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
…ju06#331)

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

* fix(api): preserve codex model visibility gating

---------

Co-authored-by: Soju06 <[email protected]>
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
* fix(proxy): preserve model_messages in catalog response

codex-lb stripped `model_messages` from upstream model entries via
`_FILTERED_FIELDS` in model_fetcher.py. The Codex client's model picker
needs this field to display newer models (gpt-5.6-sol/terra/luna);
without it the client silently drops models absent from its bundled
metadata. PR Soju06#331 removed `base_instructions` from the filter for the
same reason — `model_messages` was left behind by oversight.

Remove the dead `_FILTERED_FIELDS` abstraction and use `raw = dict(data)`
to preserve all upstream fields verbatim, making the catalog response
field-for-field identical to the upstream ChatGPT backend response.

Adds regression tests at the fetcher boundary and the catalog endpoint,
plus an OpenSpec change folder.

* chore(pr): finalize preserve-model-messages-in-catalog for merge

- Merge origin/main into the PR branch.
- Add zepx (Choong Jun Jin) to .all-contributorsrc (code, test).
- Check off completed tasks in the OpenSpec change tasks.md.
- Add a direct client_version-path regression test asserting
  GET /v1/models?client_version=<v> preserves model_messages for a
  live-catalog model.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Soju06 <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
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