ollama-js

Official JavaScript/TypeScript client for chatting, streaming, and generating with local or cloud-hosted Ollama models.

SDK
npm
v0.6.3
4,362stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
51/100Fair
Development Activity4
Maintenance44
Community68
Maturity48
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture78
Code Quality78
Innovation72
Learning Curve60

Ollama-js is the official JavaScript and TypeScript client for the Ollama API, giving Node.js and browser applications typed access to large language models running through the Ollama server. It wraps every core endpoint — chat, generate, create, pull, push, embed, and more — behind a single Ollama class, with matching streaming and non-streaming overloads for each method.

Beyond local inference, the library also talks to Ollama’s hosted cloud API at ollama.com, letting the same client code offload larger models to the cloud by swapping the host and adding an API key. A Node-specific subclass adds local file handling for image inputs and model creation, while a lightweight browser build keeps the footprint minimal for client-side use.

What You Get

  • A single Ollama client class covering chat, generate, create, pull, push, copy, delete, list, show, embed, and ps endpoints
  • Matching streaming and non-streaming TypeScript overloads for every request method, backed by an AbortableAsyncIterator
  • A custom ResponseError class carrying the HTTP status code for structured error handling
  • Separate Node and browser entry points, with the Node build adding local file-based image and model handling
  • Direct access to Ollama’s hosted cloud API (ollama.com) for offloading larger models without changing client code

Common Use Cases

  • Building a local chatbot or coding assistant against models running on a developer’s own machine
  • Streaming token-by-token chat or generate responses into a CLI or web UI
  • Generating text embeddings for retrieval-augmented generation (RAG) pipelines
  • Offloading larger models to Ollama’s cloud API when local hardware isn’t enough
  • Managing the local model library programmatically — pulling, listing, copying, and deleting models from scripts

Under The Hood

Architecture The library is built around a single Ollama class defined in src/browser.ts, which every request method (chat, generate, embed, pull, push, etc.) funnels through a shared processStreamableRequest helper — this one method decides whether to return a plain JSON response or wrap the response body in an AbortableAsyncIterator (from src/utils.ts) depending on the request’s stream flag, so every endpoint gets streaming support for free. A Node-specific Ollama subclass in src/index.ts extends the browser class to add filesystem-aware behavior — resolving local image paths to base64 and rejecting local-path model creation — while the browser entry point stays dependency-light. Configuration (host, custom fetch implementation, headers) is injected through the constructor rather than read from globals, so a single fetch swap is enough to redirect the client at a proxy, mock server, or Ollama’s own cloud endpoint.

Tech Stack Written in strict TypeScript and built with unbuild into dual ESM/CommonJS bundles (dist/index.mjs / dist/index.cjs) plus generated .d.ts type declarations, so it works from both import and require call sites. The only runtime dependency is whatwg-fetch, a fetch polyfill for browser environments; everything else (typed request/response interfaces, the streaming NDJSON parser, header normalization) is hand-written rather than pulled from a third-party HTTP client. Tests run on Vitest, linting on ESLint with the TypeScript plugin, and formatting on Prettier.

Code Quality A test/ directory covers the browser client, Node client, and utility functions with Vitest, using vi.spyOn to assert that request options (model, streaming flags, logprobs, tool calls) are forwarded correctly to the underlying transport rather than hitting a live server — a reasonable unit-level substitute for integration tests. Errors surface as a dedicated ResponseError class carrying both a message and the original HTTP status code, rather than being swallowed or re-thrown as generic Errors. tsconfig.json enables strict mode with strictNullChecks, and CI (.github/workflows/test.yaml) runs the test suite on every change, with a separate publish.yaml workflow handling npm releases.

API Design The public surface mirrors the Ollama HTTP API almost one-to-one — chat(), generate(), pull(), embed(), and friends each take a single typed request object and return either the full response or a stream, selected purely by a stream boolean, so callers don’t need two different client shapes for the two modes. Getting started requires only new Ollama() and one call; more advanced features (tool calling via a tools array, JSON-constrained output via format, reasoning depth via think, and per-token logprobs) are opt-in fields on the same request objects rather than separate methods, keeping the API surface small while still exposing the full range of the underlying server’s capabilities.

Used by 11 apps in this directory

TypeScript
53%
MIT

Anarlog

Note Taking · AI Assistants · Productivity

9,252

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
68
Dependency
Built with
TypeScript53%
Rust35%
Updated today
JavaScript
95%
MIT

AnythingLLM

Developer Tools · Automation · AI Assistants

65,696

The all-in-one AI platform for private document chat, no-code agents, and local LLMs with zero setup friction.

View details
90
Repo Health
78
Technical
64
Dependency
Built with
JavaScript95%
Updated 3 days ago
TypeScript
72%
MIT

Claude Context

AI Code Assistants

12,498

An MCP server and VS Code extension by Zilliz that turns your entire codebase into semantically searchable context for Claude Code, Cursor, and Gemini CLI, using vector embeddings and Merkle-tree change detection.

View details
49
Repo Health
71
Technical
71
Dependency
Built with
TypeScript72%
Python13%
JavaScript11%
Updated 1 months ago
TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,808

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
81
Repo Health
88
Technical
62
Dependency
Built with
TypeScript84%
Updated yesterday
TypeScript
62%
Other

Flowise

Developer Tools · Automation · No Code Platforms

55,427

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
86
Repo Health
77
Technical
63
Dependency
Built with
TypeScript62%
JavaScript27%
Updated 3 weeks ago
Rust
67%
Other

GitButler

Developer Tools · Devops · AI Development

21,624

Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.

View details
89
Repo Health
84
Technical
67
Dependency
Built with
Rust67%
TypeScript20%
Svelte11%
Updated yesterday
TypeScript
99%
AGPL 3.0

Karakeep

Bookmarks Archiving

28,871

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript99%
Updated 1 weeks ago
TypeScript
81%
MIT

LibreChat

Developer Tools · AI Assistants

42,871

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
65
Dependency
Built with
TypeScript81%
JavaScript18%
Updated today
TypeScript
99%
Other

LobeHub

AI Assistants · Productivity · Automation

82,273

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
69
Dependency
Built with
TypeScript99%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search