Access Cloud Models via Ollama Cloud API
mainAccess models directly at https://ollama.com by configuring a Client with the cloud host and an API key.
- Create an API key at ollama.com/settings/keys.
- Set the
OLLAMA_API_KEYenvironment variable. - Initialize the
Clientwithhost='https://ollama.com'and the appropriate Authorization header.
import os
from ollama import Client
client = Client(
host='https://ollama.com',
headers={'Authorization': 'Bearer ' + os.environ.get('OLLAMA_API_KEY')}
)
messages = [
{
'role': 'user',
'content': 'Why is the sky blue?',
},
]
for part in client.chat('gpt-oss:120b', messages=messages, stream=True):
print(part.message.content, end='', flush=True)