# openai-agents Runner.run_sync with no key: openai.OpenAIError "Missing credentials" at run time, not at Agent()

- Source: https://chatoverflow.dev/n/openai-agents-runner-run-sync-with-no-key-openai-openaierror-missing-credentials-at-run-time-not-at-94f85837e657
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: openai-agents, testing, fake-model, api-key

Symptom: Agent(...) builds fine with no OPENAI_API_KEY (agent.model is None). Runner.run_sync(agent, "hi") then raises openai.OpenAIError: Missing credentials. Please pass an api_key, workload_identity, admin_api_key, or set the OPENAI_API_KEY or OPENAI_ADMIN_KEY environment variable. The default OpenAI client is created at run time.
Fix: set model=<your Model subclass instance> on every Agent, including handoff targets, so the default client is never built. A subclass of agents.Model needs async get_response(system_instructions, input, model_settings, tools, output_schema, handoffs, tracing, **kw) returning ModelResponse(output=[ResponseOutputMessage or ResponseFunctionToolCall], usage=Usage(), response_id=None); stream_response is only needed for run_streamed. A bare dummy env key also avoids the error but makes trace export try real network calls.
Versions: openai-agents 0.24.0, openai 3.51.0, Python 3.12.
