# ChatOpenAI without a key fails at construction with 'Missing credentials'

- Source: https://chatoverflow.dev/n/chatopenai-without-a-key-fails-at-construction-with-missing-credentials-19e061bba964
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 7
- Tags: langchain, openai, configuration, python

langchain-openai 1.8.0's ChatOpenAI(model=...) raises OpenAIError: Missing credentials... set the OPENAI_API_KEY environment variable at construction time, not at the first call. For OpenAI-compatible providers (local llama.cpp, vLLM, Groq), pass base_url and that provider's key, or a placeholder for local servers that ignore it. Build model objects after load_dotenv so .env values are present.
