different-ai/openwork · error · Error
OpenAI API key required for computer use.
Error message
OpenAI API key required for computer use.
What it means
runCuaLoop drives an OpenAI computer-use agent loop (screenshot → model → action). It refuses to start when the apiKey argument is missing, empty, or whitespace-only, because every turn calls the OpenAI Responses API which requires bearer credentials. The check is a fail-fast guard before any tool calls or network requests are made.
Source
Thrown at packages/handsfree/src/cua-runner.mjs:13
export const CUA_DEFAULT_MODEL = "gpt-5.5";
export const CUA_MAX_TURNS = 30;
export async function runCuaLoop({
task,
apiKey,
callTool,
onProgress,
signal,
model = CUA_DEFAULT_MODEL,
maxTurns = CUA_MAX_TURNS,
}) {
if (!apiKey?.trim()) throw new Error("OpenAI API key required for computer use.");
if (typeof callTool !== "function") throw new Error("callTool is required.");
const display = await callTool("display_info", {});
const displayInfo = parseToolText(display) ?? { width: 1440, height: 900 };
onProgress?.({ kind: "start", width: displayInfo.width, height: displayInfo.height });
const items = [{ role: "user", content: String(task ?? "") }];
const messages = [];
for (let turn = 0; turn < maxTurns; turn += 1) {
if (signal?.aborted) return { ok: true, messages, turns: turn, aborted: true };
onProgress?.({ kind: "turn", turn: turn + 1 });
const response = await fetch("https://api.openai.com/v1/responses", {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
body: JSON.stringify({ model, input: items, tools: [{ type: "computer" }] }),
signal,View on GitHub (pinned to 2b7df46e8a)
Solutions
- Set OPENAI_API_KEY in the environment or .env file the runner process actually loads, then verify with `echo ${OPENAI_API_KEY:+set}`.
- Pass apiKey explicitly: runCuaLoop({ apiKey: <resolved key>, callTool, ... }) instead of relying on ambient env resolution.
- Validate the key before starting the loop: `if (!apiKey?.trim()) throw ...` mirrors the library check, so add your own preflight with a clearer message.
- If using a proxy/gateway that injects auth, wrap callTool so the key requirement is satisfied or patch the options to forward the gateway token as apiKey.
Example fix
// before
await runCuaLoop({ callTool, onProgress })
// after
await runCuaLoop({ apiKey: process.env.OPENAI_API_KEY!, callTool, onProgress }) Defensive patterns
Strategy: validation
Validate before calling
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey || !apiKey.trim()) throw new Error("Set OPENAI_API_KEY before running the CUA loop"); Prevention
- Load and assert env vars at process startup, not at call time
- Add a startup preflight that checks required keys per feature (computer use, embeddings, etc.)
- Keep one canonical key name per provider and document it
When it happens
Trigger: Calling runCuaLoop without passing apiKey, with apiKey: process.env.OPENAI_API_KEY when that env var is unset, or with an empty/whitespace string (""). Any callTool implementation will not be invoked — the throw happens first.
Common situations: Deployed environment (CI, server, sandboxed app) where OPENAI_API_KEY was never set or was stripped by the .env loader; key renamed to a vendor-specific var (e.g. using an OpenWork/BYOK gateway variable) while the runner still expects OPENAI_API_KEY; apiKey passed via a config object where the field is optional and silently undefined.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- t("providers.no_providers_available")
- Sign in to OpenWork Cloud and choose an organization first.
- `${provider.name} does not have a stored organization creden
- Missing Google OAuth configuration: ${missing.join(", ")}
- unsupported_transport
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/85db144e9e095b7e.
Report an issue: GitHub.