Local API Access
No authentication is required when accessing Ollama’s API locally viahttp://localhost:11434.
Local access is unrestricted by default. If you need to secure your local Ollama instance, consider using a reverse proxy with authentication or firewall rules.
When Authentication is Required
Authentication is required for the following use cases:Cloud Models
Running cloud-based models via ollama.com
Publishing Models
Pushing models to the Ollama registry
Private Models
Downloading private models from the registry
Remote Inference
Accessing ollama.com’s hosted inference API
Authentication Methods
Ollama supports two authentication methods:Method 1: Signing In (Recommended)
Sign in from your local Ollama installation, and authentication is handled automatically:Sign in to Ollama
Run the signin command in your terminal:You’ll be prompted to complete the authentication flow via your browser.
Use authenticated commands
Once signed in, Ollama automatically authenticates commands that require it:
When you sign in, Ollama stores authentication credentials locally and automatically includes them in requests that need authentication.
Method 2: API Keys
For programmatic access to ollama.com’s API (https://ollama.com/api), use API keys for authentication.
Create an API key
Generate an API key from your Ollama settings page.
API Key Management
- Expiration: API keys don’t currently expire automatically
- Revocation: You can revoke keys at any time in your API keys settings
- Multiple keys: Create multiple keys for different applications or environments
Authentication Flow Details
When using authenticated requests, Ollama implements a secure challenge-response authentication mechanism:- Timestamp-based challenges: Each request includes a timestamp (
ts) parameter to prevent replay attacks - Signed tokens: Authentication tokens are cryptographically signed using your local credentials
- Automatic token refresh: The client handles token refresh transparently
The authentication implementation can be found in
api/client.go and server/auth.go in the Ollama source code.Error Handling
When authentication fails, you’ll receive a401 Unauthorized response:
signin_url field provides a direct link to authenticate your installation.
Signing Out
To remove stored authentication credentials from your local installation:Environment Variables
Ollama respects the following authentication-related environment variables:| Variable | Description | Default |
|---|---|---|
OLLAMA_HOST | Base URL for API requests | http://localhost:11434 |
OLLAMA_API_KEY | API key for ollama.com authentication | None |
Best Practices
Use Environment Variables
Store API keys in environment variables, never in code
Rotate Keys Regularly
Periodically create new keys and revoke old ones
Use Signin for Local Dev
The
ollama signin method is simpler for local developmentUse API Keys for CI/CD
API keys are better for automated deployments and services
Next Steps
Client Libraries
Use Python or JavaScript libraries with built-in auth support
Generate Text
Start generating text with authenticated models
Error Handling
Learn how to handle authentication errors