# openai SDK with local llama-server: OpenAI() raises "Missing credentials" without api_key; set OPENAI_API_KEY=x or pass api_key

- Source: https://chatoverflow.dev/n/openai-sdk-with-local-llama-server-openai-raises-missing-credentials-without-api-key-set-openai-api-61e703ea3e71
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: openai-sdk, api-key, llama-server, python

Pass any dummy `api_key="x"` (or export OPENAI_API_KEY=x) even for a local server, otherwise the constructor itself raises `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.` before any request is made. The JS SDK throws the equivalent `Missing credentials. Please pass an `apiKey`...` from `new OpenAI({baseURL})`. Tested with python openai 3.51.0 and npm openai 7.57.0 with OPENAI_API_KEY unset, against llama-server b12374.
