cloudflare / cloudflare/moltworker

`OPENAI_API_KEY` alone produces silent empty responses

Open
#280 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
10k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

### Summary

Setting only `OPENAI_API_KEY` (without `ANTHROPIC_API_KEY` or AI Gateway config) results in the chatbot returning empty responses with no error messages. The root cause is that `openclaw onboard --auth-choice openai-api-key` saves the key to `~/.openclaw/.env` but does not set `agents.defaults.model` in the config, so the gateway defaults to `anthropic/claude-opus-4-5` — which fails silently with no Anthropic key.

### Steps to Reproduce

1. Deploy moltworker with only `OPENAI_API_KEY` set (no `ANTHROPIC_API_KEY`, no AI Gateway secrets)
2. Open the Control UI and send a message
3. The assistant responds with an empty message — no error, no indication of what went wrong

### Root Cause

In `start-openclaw.sh`, the onboard step runs:

```bash
openclaw onboard --non-interactive --accept-risk \
--auth-choice openai-api-key --openai-api-key $OPENAI_API_KEY \
...
```

This correctly saves the API key to `~/.openclaw/.env`, but the resulting `openclaw.json` has no `agents.defaults.model` entry. The gateway then falls back to `anthropic/claude-opus-4-5` as the default model, which requires an Anthropic API key that isn't configured.

The `CF_AI_GATEWAY_MODEL` override block in the config patch handles AI Gateway models, but there's no equivalent fallback for direct `OPENAI_API_KEY` usage.

### Expected Behavior

Setting `OPENAI_API_KEY` alone should work out of the box. The config patch should detect this case and set the default model to `openai/gpt-4o` (or another OpenAI model).

### Proposed Fix

Add a fallback block in the `start-openclaw.sh` config patch (after the `CF_AI_GATEWAY_MODEL` block) that detects when `OPENAI_API_KEY` is set without an AI Gateway model override and sets the default model accordingly:

```javascript
if (process.env.OPENAI_API_KEY && !process.env.CF_AI_GATEWAY_MODEL) {
const currentModel = config.agents?.defaults?.model?.primary || '';
if (!currentModel || currentModel.startsWith('anthropic/')) {
config.agents = config.agents || {};
config.agents.defaults = config.agents.defaults || {};
config.agents.defaults.model = { primary: 'openai/gpt-4o' };
}
}
```

Additionally, the README should be updated to list `OPENAI_API_KEY` as a standalone alternative to `ANTHROPIC_API_KEY` in the Requirements and Quick Start sections.

### Environment

- moltworker deployed on Cloudflare Sandbox
- `openclaw@2026.2.3` (container image)
- Only `OPENAI_API_KEY` set as AI provider secret

### AI Disclosure

This issue was investigated and drafted with assistance from Claude Code. The bug was discovered through manual testing and confirmed by inspecting `/debug/container-config` and `/debug/processes?logs=true` outputs. The proposed fix has been tested and verified on a live deployment.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.