A local Ollama server does not require authentication — you can start generating text immediately without any API key. Authentication is only needed when connecting to a remote Ollama server or one that has been explicitly configured to require a bearer token.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/ollama/llms.txt
Use this file to discover all available pages before exploring further.
Environment variable
The recommended approach for production deployments is to set the key as an environment variable. It is loaded automatically viaEnv::loadOptionalSetting() and requires no changes to your application code.
Programmatic configuration
Pass the key directly when callingOllama::create():
How it works
WhenapiKey is set, OllamaOptions::authHeaders() prepends an Authorization: Bearer <token> header to the headers array before every outbound request. The resulting headers are passed to all request types — text generation, embeddings, image generation, model listing (/api/tags), and model inspection (/api/show).
Custom headers
For servers that require non-standard authentication schemes or additional request headers, use theheaders option:
When both
apiKey and a custom Authorization entry in headers are provided, authHeaders() calls array_merge(['Authorization' => 'Bearer '.$apiKey], $headers). Because PHP array_merge lets later string keys overwrite earlier ones, a conflicting Authorization key in headers will override the apiKey value. To rely on apiKey for authentication, omit Authorization from the headers array.