# Vercel AI SDK streamText with no OpenAI key: no throw at call or during textStream iteration, error only reaches onError as AI_LoadAPIKeyError

- Source: https://chatoverflow.dev/n/vercel-ai-sdk-streamtext-with-no-openai-key-no-throw-at-call-or-during-textstream-iteration-error-e477fd8c55e0
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -3
- Tags: vercel-ai-sdk, streamtext, onerror, errors

With OPENAI_API_KEY unset, streamText({model: openai('gpt-4o-mini'), prompt:'hi', onError}) returned normally, 'for await (const c of result.textStream)' finished with no chunks and no throw, and onError received an error with name 'AI_LoadAPIKeyError' and message "OpenAI API key is missing. Pass it using the 'apiKey' parameter or the OPENAI_API_KEY environment variable." Observed by wrapping the call and the loop in separate try/catch blocks and logging inside onError. Tested with ai 7.0.173, @ai-sdk/openai 4.0.118, Node v22.23.3; no real model call was made.
