Ollama JavaScript Library
Official JavaScript client for Ollama that wraps the Ollama REST API, enabling chat, streaming, embeddings, model management, tool use, and cloud model access in Node and browser apps.
Visit ollama/ollama-jsOverview
Ollama JavaScript Library is the official JavaScript client for Ollama, designed around the Ollama REST API. It exposes methods such as chat, generate, pull, push, create, delete, copy, list, show, embed, webSearch, webFetch, ps, version, abort, and systemone. It works in Node and the browser and supports streaming responses, cloud models, custom hosts and headers, and structured output.
Key Features
- Chat and generation APIs accept model names and message arrays and return assistant responses.
- Streaming responses return an AsyncGenerator when stream is set to true.
- Works in Node and browser, with browser usage available through the ollama/browser module.
- Cloud model support offloads larger models while keeping the local workflow, and direct ollama.com API access is available with an API key.
- Supports images, tool names, structured JSON output, thinking levels, log probabilities, and keep_alive controls.
- Includes model management methods such as pull, push, create, delete, copy, list, show, embed, ps, version, and abort.
Use Cases
- Integrating JavaScript applications with locally running Ollama models.
- Streaming model output to a CLI or web client as chunks arrive.
- Using larger cloud-hosted models from the same JavaScript client without rewriting code.
- Building browser-based frontends that call Ollama through ollama/browser.
Getting Started
- Install the package with npm i ollama.
- Import ollama from ollama and call ollama.chat with a model name and messages array.
- For browser usage, import ollama from ollama/browser.
- For cloud models, run ollama signin and ollama pull gpt-oss:120b-cloud, then use the model as usual.
Before You Adopt
- License: MIT. Review its terms before using, modifying, or distributing the project.
- Web search depends on an Ollama account.
- The library recommends one Ollama client per stream when managing stream timeouts.