Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ response = client.chat(
)
```

### HTTP Basic authentication

For an Ollama server behind a reverse proxy that requires HTTP Basic authentication, pass an [`httpx.BasicAuth`](https://www.python-httpx.org/advanced/authentication/#basic-authentication) instance through the client's `auth` argument. Supply credentials separately from the `host` URL, whose user information is not preserved by the client's host parsing.

```python
import os
import httpx
from ollama import Client

with Client(
host='https://ollama.example.com',
auth=httpx.BasicAuth(os.environ['OLLAMA_USERNAME'], os.environ['OLLAMA_PASSWORD']),
) as client:
response = client.chat(
model='gemma4',
messages=[{'role': 'user', 'content': 'Why is the sky blue?'}],
)
print(response.message.content)
```

Set `OLLAMA_USERNAME` and `OLLAMA_PASSWORD` to the credentials configured on your reverse proxy. The same `auth` argument works with `AsyncClient`.

## Async client

The `AsyncClient` class is used to make asynchronous requests. It can be configured with the same fields as the `Client` class.
Expand Down