Sync ollama docs from eab97e9f on 2026-10-12
This commit is contained in:
+29
-35
@@ -2,34 +2,52 @@
|
||||
title: Authentication
|
||||
---
|
||||
|
||||
No authentication is required when accessing Ollama's API locally via `http://localhost:11434`.
|
||||
The local API at `http://localhost:11434` does not require authentication.
|
||||
|
||||
Authentication is required for the following:
|
||||
To use cloud models, publish models, or download private models, sign in to Ollama. For direct API access to ollama.com, use an API key.
|
||||
|
||||
* Running cloud models via ollama.com
|
||||
* Publishing models
|
||||
* Downloading private models
|
||||
## API keys
|
||||
|
||||
Ollama supports two authentication methods:
|
||||
Direct cloud inference at `https://ollama.com/api` and `https://ollama.com/v1` requires an API key. No Ollama installation or local server is required.
|
||||
|
||||
* **Signing in**: sign in from your local installation, and Ollama will automatically take care of authenticating requests to ollama.com when running commands
|
||||
* **API keys**: API keys for programmatic access to ollama.com's API
|
||||
Create an [API key](https://ollama.com/settings/keys), then set it in your terminal:
|
||||
|
||||
```shell
|
||||
export OLLAMA_API_KEY="your_api_key"
|
||||
```
|
||||
|
||||
Use the API key in the `Authorization: Bearer` header. This also applies to the hosted Anthropic-compatible `/v1/messages` endpoint; `x-api-key` alone is not supported.
|
||||
|
||||
```shell
|
||||
curl https://ollama.com/api/chat \
|
||||
-H "Authorization: Bearer $OLLAMA_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "gemma4:31b",
|
||||
"messages": [{"role": "user", "content": "Why is the sky blue?"}],
|
||||
"stream": false
|
||||
}'
|
||||
```
|
||||
|
||||
API keys do not expire. Revoke a key in [API keys settings](https://ollama.com/settings/keys).
|
||||
|
||||
Keep keys outside browser code and source control. See the [API quickstart](/quickstart#build-an-application) for shell setup and compatibility examples.
|
||||
|
||||
## Signing in
|
||||
|
||||
To sign in to ollama.com from your local installation of Ollama, run:
|
||||
Sign in from your terminal:
|
||||
|
||||
```
|
||||
ollama signin
|
||||
```
|
||||
|
||||
Once signed in, Ollama will automatically authenticate commands as required:
|
||||
Ollama then authenticates cloud requests for you:
|
||||
|
||||
```
|
||||
ollama run gpt-oss:120b-cloud
|
||||
```
|
||||
|
||||
Similarly, when accessing a local API endpoint that requires cloud access, Ollama will automatically authenticate the request:
|
||||
This also works through the local API:
|
||||
|
||||
```shell
|
||||
curl http://localhost:11434/api/generate -d '{
|
||||
@@ -37,27 +55,3 @@ curl http://localhost:11434/api/generate -d '{
|
||||
"prompt": "Why is the sky blue?"
|
||||
}'
|
||||
```
|
||||
|
||||
## API keys
|
||||
|
||||
For direct access to ollama.com's API served at `https://ollama.com/api`, authentication via API keys is required.
|
||||
|
||||
First, create an [API key](https://ollama.com/settings/keys), then set the `OLLAMA_API_KEY` environment variable:
|
||||
|
||||
```shell
|
||||
export OLLAMA_API_KEY=your_api_key
|
||||
```
|
||||
|
||||
Then use the API key in the Authorization header:
|
||||
|
||||
```shell
|
||||
curl https://ollama.com/api/generate \
|
||||
-H "Authorization: Bearer $OLLAMA_API_KEY" \
|
||||
-d '{
|
||||
"model": "gpt-oss:120b",
|
||||
"prompt": "Why is the sky blue?",
|
||||
"stream": false
|
||||
}'
|
||||
```
|
||||
|
||||
API keys don't currently expire, however you can revoke them at any time in your [API keys settings](https://ollama.com/settings/keys).
|
||||
|
||||
Reference in New Issue
Block a user