fix: set default model to openai/gpt-4o when only OPENAI_API_KEY is provided#323
Open
themavik wants to merge 1 commit intocloudflare:mainfrom
Open
fix: set default model to openai/gpt-4o when only OPENAI_API_KEY is provided#323themavik wants to merge 1 commit intocloudflare:mainfrom
themavik wants to merge 1 commit intocloudflare:mainfrom
Conversation
…rovided When OPENAI_API_KEY is the only provider key set (no CF_AI_GATEWAY_MODEL), the config patch does not set agents.defaults.model. The gateway then falls back to its built-in default model which requires a different provider key, causing silent empty responses. Add a fallback in the config patch that sets `openai/gpt-4o` as the default model when OPENAI_API_KEY is present but no explicit model override or existing default is configured. Closes cloudflare#280 Made-with: Cursor
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.
Summary
agents.defaults.modeltoopenai/gpt-4owhenOPENAI_API_KEYis the only provider key configuredProblem
When a user sets only
OPENAI_API_KEY(noANTHROPIC_API_KEY, noCF_AI_GATEWAY_MODEL), the chatbot returns empty responses with no error. Theopenclaw onboardstep correctly saves the OpenAI key, but the config patch instart-openclaw.shnever setsagents.defaults.model. The gateway then falls back to its built-in default model (which requires a provider key that isn't configured), and fails silently.Root Cause
The config patch only sets
agents.defaults.modelinside theCF_AI_GATEWAY_MODELblock (line 183+). When that env var is absent, no default model is ever written, regardless of which provider keys are available.Fix
Add an OpenAI-only fallback block before the
CF_AI_GATEWAY_MODELhandler. WhenOPENAI_API_KEYis set andCF_AI_GATEWAY_MODELis not, and noagents.defaults.modelexists in the config, set it to{ primary: "openai/gpt-4o" }.The guard
!config.agents.defaults.modelensures we never overwrite a user-configured default, and the!process.env.CF_AI_GATEWAY_MODELguard ensures the existing AI Gateway path still takes full control when present.Testing
OPENAI_API_KEYset: config now hasagents.defaults.model.primary = "openai/gpt-4o"OPENAI_API_KEYandCF_AI_GATEWAY_MODELset: AI Gateway block handles it (no change)ANTHROPIC_API_KEYset: no change (onboard configures the default via its own logic)agents.defaults.modelin R2-restored config: preserved (guard prevents overwrite)Closes #280