Skip to content

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
themavik:fix/openai-only-default-model
Open

fix: set default model to openai/gpt-4o when only OPENAI_API_KEY is provided#323
themavik wants to merge 1 commit intocloudflare:mainfrom
themavik:fix/openai-only-default-model

Conversation

@themavik
Copy link

@themavik themavik commented Mar 18, 2026

Summary

  • Set agents.defaults.model to openai/gpt-4o when OPENAI_API_KEY is the only provider key configured

Problem

When a user sets only OPENAI_API_KEY (no ANTHROPIC_API_KEY, no CF_AI_GATEWAY_MODEL), the chatbot returns empty responses with no error. The openclaw onboard step correctly saves the OpenAI key, but the config patch in start-openclaw.sh never sets agents.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.model inside the CF_AI_GATEWAY_MODEL block (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_MODEL handler. When OPENAI_API_KEY is set and CF_AI_GATEWAY_MODEL is not, and no agents.defaults.model exists in the config, set it to { primary: "openai/gpt-4o" }.

The guard !config.agents.defaults.model ensures we never overwrite a user-configured default, and the !process.env.CF_AI_GATEWAY_MODEL guard ensures the existing AI Gateway path still takes full control when present.

Testing

  • With only OPENAI_API_KEY set: config now has agents.defaults.model.primary = "openai/gpt-4o"
  • With both OPENAI_API_KEY and CF_AI_GATEWAY_MODEL set: AI Gateway block handles it (no change)
  • With only ANTHROPIC_API_KEY set: no change (onboard configures the default via its own logic)
  • With an existing agents.defaults.model in R2-restored config: preserved (guard prevents overwrite)

Closes #280

…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
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.

OPENAI_API_KEY alone produces silent empty responses

2 participants