Ollama client libraries: ollama-python / ollama-js / Go api package
Parent: Ollama integrations and ecosystem · Published reference · snapshot 2026-10-14 · skill ollama-expert/references/ollama-integrations-ecosystem.md
Also known as: Ollama client libraries: ollama-python, ollama-js, Go api package
↓ Facts as markdownall context files
Everything the scanned sources say about Ollama client libraries: ollama-python, ollama-js, Go api package: 83 source-anchored units across 8 sources, grouped by facet.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Definitions
- The Go client is the `api` package inside the main `github.com/ollama/ollama` module, not a separate module. `api.ClientFromEnvironment()` reads OLLAMA_HOST; `Generate` and `Chat` stream to a callback. The ollama CLI itself uses this package. [source]
- Note: The files parameter is not currently supported in ollama-js. [source]
Structure and components
- Part 2 — Calling Ollama via the official Go SDK (github.com/ollama/ollama/api) [source]
- const ollama = new Ollama() const response = await ollama.chat({ model: 'gpt-oss:120b-cloud', messages: [{ role: 'user', content: 'Explain quantum computing' }], stream: true, }) for await (const part of response) { process.stdout.write(part.message.content) } [source]
- async def chat(): message = {'role': 'user', 'content': 'Why is the sky blue?'} async for part in await AsyncClient().chat(model='gemma4', messages=[message], stream=True): print(part['message']['content'], end='', flush=True) [source]
How it works
- const ollama = new Ollama({ host: 'https://ollama.com', headers: { Authorization: 'Bearer ' + process.env.OLLAMA_API_KEY }, }) [source]
Examples and snippets
- ```json theme={"system"} — `"custom_models": [` … [source]
- ```typescript — `import { Ollama } from 'ollama';` … [source]
- ```python theme={"system"} — `import os` … [source]
- ```json theme={"system"} — `"custom_models": [` … [source]
- ```shell theme={"system"} — `export POOLSIDE_STANDALONE_BASE_URL=http://localhost:11434/v1` … [source]
- ```shell theme={"system"} — `POOLSIDE_STANDALONE_BASE_URL=http://localhost:11434/v1 POOLSIDE_API_KEY=ollama pool -m kimi-k2.6:cloud` … [source]
- ```typescript — `import { ollama } from 'ai-sdk-ollama';` … [source]
- ```typescript — `import { ollama, generateText, streamText } from 'ai-sdk-ollama';` … [source]
- ```typescript — `import { ollama, generateText, streamText } from 'ai-sdk-ollama';` … [source]
- ```shell theme={"system"} — `curl http://localhost:11434/v1/messages \` … [source]
- ```shell theme={"system"} — `export COPILOT_PROVIDER_BASE_URL=http://localhost:11434/v1` … [source]
- ```shell theme={"system"} — `COPILOT_PROVIDER_BASE_URL=http://localhost:11434/v1 COPILOT_PROVIDER_API_KEY= COPILOT_PROVIDER_WIRE_API=respon` … [source]
Measurements and reference values
- response = client.chat.completions.create( model='qwen3-vl:8b', messages=[ { 'role': 'user', 'content': [ {'type': 'text', 'text': "What's in this image?"}, { 'type': 'image_url', 'image_url': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG0AAABmCAYAAADBPx+VAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA3VSURBVHgB7Z27r0zdG8fX743i1bi1ikMoFMQloXRpKFFIqI7LH4BEQ+NWIkjQuSWCRIEoULk0gsK1kCBI0IhrQVT7tz/7zZo888yz1r7MnDl7z5xvsjkzs2fP3uu71nNfa7lkAsm7d++Sffv2JbNmzUqcc8m0adOSzZs3Z+/XES4ZckAWJEGWPiCxjsQNLWmQsWjRIpMseaxcuTKpG/7HP27I8P79e7dq1ars/yL4/v27S0ejqwv+cUOGEGGpKHR37tzJCEpHV9tn [source]
- const response = await openai.chat.completions.create({ model: "qwen3-vl:8b", messages: [ { role: "user", content: [ { type: "text", text: "What's in this image?" }, { type: "image_url", image_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG0AAABmCAYAAADBPx+VAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA3VSURBVHgB7Z27r0zdG8fX743i1bi1ikMoFMQloXRpKFFIqI7LH4BEQ+NWIkjQuSWCRIEoULk0gsK1kCBI0IhrQVT7tz/7zZo888yz1r7MnDl7z5xvsjkzs2fP3uu71nNfa7lkAsm7d++Sffv2JbNmzUqcc8m0adOSzZs3Z+/XES4ZckAWJEGWPiCxjsQNLWmQsWjRIpMseaxcuTKpG/7HP27I8P79e7dq1ars/yL4/v27S0ejqwv+cUOGEGGpKHR37tzJCEp [source]
- ```shell vision.sh theme={"system"} curl -X POST http://localhost:11434/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3-vl:8b", "messages": [{ "role": "user", "content": [{"type": "text", "text": "What is this an image of?"}, {"type": "image_url", "image_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG0AAABmCAYAAADBPx+VAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA3VSURBVHgB7Z27r0zdG8fX743i1bi1ikMoFMQloXRpKFFIqI7LH4BEQ+NWIkjQuSWCRIEoULk0gsK1kCBI0IhrQVT7tz/7zZo888yz1r7MnDl7z5xvsjkzs2fP3uu71nNfa7lkAsm7d++Sffv2JbNmzUqcc8m0adOSzZs3Z+ [source]
Problems, failure modes and limitations
- Antipattern: sharing one ollama-js client across streams you want to cancel independently; `abort()` kills every stream on the client, and a user issue requests built-in timeout cancellation and better error categories. [source]
- func chatWithQwen3Thinking(ctx context.Context, thinking bool) error { client, err := api.ClientFromEnvironment() // honors OLLAMA_HOST if set if err != nil { return err } [source]
- func chatWithGptOss(ctx context.Context) error { client, err := api.ClientFromEnvironment() if err != nil { return err } req := &api.ChatRequest{ Model: "gpt-oss:20b", Think: api.Ptr(true), Messages: []api.Message{ {Role: "user", Content: "What is memoization and when is it useful?"}, }, } var resp api.ChatResponse if err := client.Chat(ctx, req, &resp); err != nil { return err } // If you intend to hide reasoning, do it here regardless of flags. if resp.Message.Thinking != "" { fmt.Println("🧠 thinking:\n", resp.Message.Thinking) } fmt.Println("\n💬 answer:\n", resp.Message.Content) return nil [source]
- func generateWithQwen3(ctx context.Context) error { client, err := api.ClientFromEnvironment() if err != nil { return err } req := &api.GenerateRequest{ Model: "qwen3:4b-thinking", Prompt: "Summarize the role of a B-Tree in indexing.", Think: api.Ptr(true), } var resp api.GenerateResponse if err := client.Generate(ctx, req, &resp); err != nil { return err } if resp.Thinking != "" { fmt.Println("🧠 thinking:\n", resp.Thinking) } fmt.Println("\n💬 answer:\n", resp.Response) return nil } [source]
- func generateWithGptOss(ctx context.Context) error { client, err := api.ClientFromEnvironment() if err != nil { return err } req := &api.GenerateRequest{ Model: "gpt-oss:20b", Prompt: "Explain gradient descent in simple terms.", Think: api.Ptr(true), } var resp api.GenerateResponse if err := client.Generate(ctx, req, &resp); err != nil { return err } if resp.Thinking != "" { fmt.Println("🧠 thinking:\n", resp.Thinking) } fmt.Println("\n💬 answer:\n", resp.Response) return nil } [source]
- func streamWithOfficialSDK(ctx context.Context) error { client, _ := api.ClientFromEnvironment() [source]
- func NewOllamaService() (*OllamaService, error) { client, err := api.ClientFromEnvironment() if err != nil { return nil, err } return &OllamaService{client: client}, nil } [source]
- func loggedChat(ctx context.Context, logger *log.Logger, req *api.ChatRequest) error { start := time.Now() client, _ := api.ClientFromEnvironment() [source]
Facts and statements
- Both Python and JS clients can use Ollama cloud models two ways: through a local Ollama after `ollama signin`, or directly by setting host to https://ollama.com with an OLLAMA_API_KEY bearer token. [source]
- Third-party wrapper check: ai-sdk-ollama, a community Vercel AI SDK provider by a non-Ollama author, states it is 'built on the official `ollama` package' (ollama-js), accepts an existing Ollama client instance, and adds tool-call follow-up text, JSON repair and web search/fetch tools needing OLLAMA_API_KEY. Each major version targets one AI SDK major (4.x targets ai@^7, 3.x ai@^6 maintenance only, 2.x unmaintained). [source]
- ollama-js installs with `npm i ollama`; Node uses `import ollama from 'ollama'` and browsers use `import ollama from 'ollama/browser'`. A custom `new Ollama({host, fetch, headers})` replaces the default host http://127.0.0.1:11434. [source]
- A newer System One endpoint (structured multiple-choice, yes/no, scored answers) appears in all three clients and needs Ollama server v0.35.0+; in ollama-js it needs a compatible model and does not support streaming or cloud models. [source]
- ollama-python installs with `pip install ollama`, supports Python 3.8+, and offers a sync `Client` and an `AsyncClient`; extra keyword arguments are passed through to httpx, and `stream=True` returns a generator (async generator for AsyncClient). [source]
- PyPI lists ollama 0.6.3 (released 2026-09-29) as the latest Python client version. [source]
- The Go api package exposes Pull, Push, Create, Copy, Delete, List, Show, ListRunning, Version, Heartbeat, Embed, Whoami and Signout; web fetch/search, cloud status, model recommendations and SystemOne are marked Experimental, so their signatures may change. pkg.go.dev showed v0.40.4 (2026-10-13) with a note that it was not the module's latest tag. [source]
- For production Go code an independent write-up (Oct 2025) recommends the official api package; LangChainGo suits chain/RAG pipelines, and community clients vary in coverage. Thinking-model quirks (GPT-OSS not disabling thinking, interleaved reasoning in streams) apply regardless of client. [source]
- 3. Set the API base URL to the Ollama OpenAI-compatible endpoint: [source]
- * [Integrations](/integrations) — connect an app, editor, or agent. * [API reference](/api/introduction) — use Ollama's API or compatible OpenAI and Anthropic clients. * [Python library](https://github.com/ollama/ollama-python) and [JavaScript library](https://github.com/ollama/ollama-js) — use Ollama from your application. [source]
- 1. In marimo, go to the user settings and go to the AI tab. From here you can find and configure Ollama as an AI provider. For local use you would typically point the base url to `http://localhost:11434/v1`. [source]
- - **Reliable tool calling** - Response synthesis adds text after tool execution, so you don't get empty replies - **Wrapper functions** - `generateText` and `streamText` return complete responses - **Built-in reliability** - Reliability features run by default - **Automatic JSON repair** - Cascade repair runs [jsonrepair](https://github.com/josdejong/jsonrepair) first, then an Ollama-specific fallback for trailing commas, comments, URLs, and Python constants - **Web search and fetch** - Built-in tools powered by [Ollama's web search API](https://ollama.com/blog/web-search) for current informat [source]
- Im interested in both sides: "pure" ollama.js and openai compatible ollama js library. [source]
- 1. Sign in to Ollama's cloud with `ollama signin` 2. In the ollama model settings add a model that ollama hosts, like `gpt-oss:120b`. 3. You can now refer to this model in marimo! [source]
- ```shell tools.sh theme={"system"} curl -X POST http://localhost:11434/v1/messages \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3-coder", "max_tokens": 1024, "tools": [ { "name": "get_weather", "description": "Get the current weather in a location", "input_schema": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state" } }, "required": ["location"] } } ], "messages": [{ "role": "user", "content": "What is the weather in San Francisco?" }] }' ``` </CodeGroup> [source]
- The official SDK automatically respects OLLAMA_HOST via api.ClientFromEnvironment(). [source]
- const ollama = new Ollama({ host: 'http://127.0.0.1:11434' }) const response = await ollama.chat({ model: 'llama3.1', messages: [{ role: 'user', content: 'Why is the sky blue?' }], }) [source]
- const ollama = new Ollama({ host: 'http://127.0.0.1:11434', headers: { Authorization: 'Bearer <api key>', 'X-Custom-Header': 'custom-value', 'User-Agent': 'MyApp/1.0', }, }) [source]
- client = OpenAI( base_url='http://localhost:11434/v1/', api_key='ollama', # required but ignored ) [source]
- const openai = new OpenAI({ baseURL: "http://localhost:11434/v1/", apiKey: "ollama", // required but ignored }); [source]
- Official Ollama Go package — Go SDK documentation [source]
- chat_completion = client.chat.completions.create( messages=[ { 'role': 'user', 'content': 'Say this is a test', } ], model='gpt-oss:20b', ) print(chat_completion.choices[0].message.content) ``` [source]
- const chatCompletion = await openai.chat.completions.create({ messages: [{ role: "user", content: "Say this is a test" }], model: "gpt-oss:20b", }); [source]
- const response = await fetch('http://localhost:11434/v1/messages', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'ollama' }, body: JSON.stringify({ model: 'qwen2.5-coder:1.5b', max_tokens: 100, messages: [{ role: 'user', content: 'Say hello in TypeScript' }], }), }); // → Response returned normally [source]
- ```shell basic.sh theme={"system"} curl -X POST http://localhost:11434/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: ollama" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "qwen3-coder", "max_tokens": 1024, "messages": [{ "role": "user", "content": "Hello, how are you?" }] }' ``` </CodeGroup> [source]
- ```shell basic.sh theme={"system"} curl -X POST http://localhost:11434/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-oss:20b", "messages": [{ "role": "user", "content": "Say this is a test" }] }' ``` </CodeGroup> [source]
- The Ollama Python library provides the easiest way to integrate Python 3.8+ projects with Ollama. [source]
- A custom client can be created by instantiating Client or AsyncClient from ollama. [source]
- import asyncio from ollama import AsyncClient [source]
- The Ollama Python library's API is designed around the Ollama REST API [source]
- Available as ollama.systemone, Client.systemone, and await AsyncClient.systemone. Question and answer types, including SystemOneResponse, are exported from ollama. See the combined question example. [source]
- 1. **Ollama API Key**: Set `OLLAMA_API_KEY` environment variable 2. **Cloud Models**: Use cloud models for optimal web search performance: - `qwen3-coder:480b-cloud` - Best for general web search - `gpt-oss:120b-cloud` - Best for complex reasoning with web data [source]
- The Ollama JavaScript library provides the easiest way to integrate your JavaScript project with Ollama. [source]
- Available on the default client and new Ollama() from both ollama and ollama/browser. Both entry points export SystemOneRequest, SystemOneResponse, and the question/answer types. Browser requests follow the server's normal CORS rules. See the combined question example. [source]
- host <string>: (Optional) The Ollama host address. Default: "http://127.0.0.1:11434". [source]
- <div> <img alt="Adding a new Ollama model" /> </div> [source]
- ```javascript tools.js theme={"system"} import Anthropic from "@anthropic-ai/sdk"; [source]
- github.com/ollama/ollama/api Official package inside the Ollama repo; used by the ollama CLI itself Full coverage mapped to REST; streaming supported Yes Considered the canonical Go client; API mirrors docs closely. [source]
- Recommendation: For production, prefer github.com/ollama/ollama/api—it’s maintained with the core project and mirrors the REST API. [source]
- go get github.com/ollama/ollama/api [source]
- "github.com/ollama/ollama/api" ) [source]
- For Go projects, github.com/ollama/ollama/api is the most complete, production-ready choice. It’s maintained alongside the Ollama core project, used by the official CLI, and provides comprehensive API coverage with guaranteed compatibility. [source]
- Production application github.com/ollama/ollama/api Official support, complete API coverage, maintained with core project [source]
- > **The problem this solves**: Standard Ollama providers can execute a tool and then return empty text. These wrapper functions synthesize a response so you get complete output. [source]
- export COPILOT_PROVIDER_BASE_URL=http://localhost:11434/v1 export COPILOT_PROVIDER_API_KEY= export COPILOT_PROVIDER_WIRE_API=responses export COPILOT_MODEL=qwen3.5 [source]
- COPILOT_PROVIDER_BASE_URL=http://localhost:11434/v1 COPILOT_PROVIDER_API_KEY= COPILOT_PROVIDER_WIRE_API=responses COPILOT_MODEL=glm-5:cloud copilot [source]
- ```shell streaming.sh theme={"system"} curl -X POST http://localhost:11434/v1/messages \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3-coder", "max_tokens": 1024, "stream": true, "messages": [{ "role": "user", "content": "Count from 1 to 10" }] }' ``` </CodeGroup> [source]
- ```shell responses.sh theme={"system"} curl -X POST http://localhost:11434/v1/responses \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3:8b", "input": "Write a short poem about the color blue" }' ``` </CodeGroup> [source]
- <Tab title="OpenAI Chat Completions"> ```shell theme={"system"} curl http://localhost:11434/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "gemma4:e2b", "messages": [ { "role": "user", "content": "Say hello in one sentence." } ] }' ``` [source]
- <Tab title="OpenAI Responses"> ```shell theme={"system"} curl http://localhost:11434/v1/responses \ -H "Content-Type: application/json" \ -d '{ "model": "gemma4:e2b", "input": "Say hello in one sentence." }' ``` [source]
- <Tab title="Anthropic Messages"> ```shell theme={"system"} curl http://localhost:11434/v1/messages \ -H "Content-Type: application/json" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "gemma4:e2b", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Say hello in one sentence." } ] }' ``` [source]
- The AsyncClient class is used to make asynchronous requests. It can be configured with the same fields as the Client class. [source]
- async def chat(): message = {'role': 'user', 'content': 'Why is the sky blue?'} response = await AsyncClient().chat(model='gemma4', messages=[message]) [source]
- client, err := api.ClientFromEnvironment() if err != nil { return nil, fmt.Errorf("creating client: %w", err) } [source]
Related concepts
- ollama — is a related of Ollama client libraries: ollama-python, ollama-js, Go api package
- openai compatibility — is a dependent of Ollama client libraries: ollama-python, ollama-js, Go api package
- api.ClientFromEnvironment — is a instance of Ollama client libraries: ollama-python, ollama-js, Go api package
- localhost — is a problem of Ollama client libraries: ollama-python, ollama-js, Go api package
- ollama-js — is a instance of Ollama client libraries: ollama-python, ollama-js, Go api package
- ollama-python — is a instance of Ollama client libraries: ollama-python, ollama-js, Go api package
- client library — is a hypernym of Ollama client libraries: ollama-python, ollama-js, Go api package
- OLLAMA_HOST — is a part of Ollama client libraries: ollama-python, ollama-js, Go api package
- tool calling — is a dependent of Ollama client libraries: ollama-python, ollama-js, Go api package
- ollama signin — is a part of Ollama client libraries: ollama-python, ollama-js, Go api package
- chat.completions — is a dependent of Ollama client libraries: ollama-python, ollama-js, Go api package
- marimo — is a instance of Ollama client libraries: ollama-python, ollama-js, Go api package
- num_ctx — is a problem of Ollama client libraries: ollama-python, ollama-js, Go api package
Children
- No children recorded.