ollama/ollama-js

Ollama JavaScript library

Ollama JavaScript Library

What it is

  • A thin client library that lets JavaScript (Node.js or browsers) talk to an Ollama server – either a local Ollama instance or Ollama’s cloud service.
  • It wraps the Ollama REST API, exposing convenient functions such as chat, generate, pull, push, create, embed, and a few newer endpoints like systemone, webSearch, and webFetch.

Why you’d use it

  • Quickly add LLM chat or text‑generation capabilities to a web app or backend without dealing with raw HTTP requests.
  • Supports streaming responses via async generators, making it easy to display partial output as it arrives.
  • Works both in Node and in the browser (via ollama/browser).
  • Can run against a locally‑installed Ollama server or directly against Ollama’s cloud (https://ollama.com) using an API key.

Key features (as described in the README)

  • Simple installation: npm i ollama.
  • Chat API – send a list of messages and get a response; optional streaming, tool calls, log‑probs, and model‑thinking levels.
  • Generate API – single‑prompt text (or image) generation with similar options.
  • Model management – pull, push, create, delete, copy, list, show for handling models on the server.
  • Embedding – obtain vector embeddings from a model.
  • Web utilities – webSearch and webFetch (cloud‑only) for search‑augmented workflows.
  • System One – a decision‑making endpoint that can ask structured questions to a model and return typed answers.
  • Custom client – you can specify a custom host, fetch implementation, and default headers (e.g., API keys, custom user‑agent).
  • Abort handling – ollama.abort() cancels all active streamed generations.

Typical usage examples

import ollama from 'ollama'   // Node
// or: import ollama from 'ollama/browser'   // browser

// Simple chat
const resp = await ollma.chat({
  model: 'llama3.1',
  messages: [{ role: 'user', content: 'Why is the sky blue?' }]
})
console.log(resp.message.content)

// Streaming chat
const stream = await ollma.chat({
  model: 'llama3.1',
  messages: [{ role: 'user', content: 'Tell me a story.' }],
  stream: true
})
for await (const part of stream) {
  process.stdout.write(part.message.content)
}

// Using the cloud API
const client = new Ollama({
  host: 'https://ollama.com',
  headers: { Authorization: 'Bearer ' + process.env.OLLAMA_API_KEY }
})
const cloudResp = await client.chat({
  model: 'gpt-oss:120b',
  messages: [{ role: 'user', content: 'Explain quantum computing' }],
  stream: true
})
for await (const part of cloudResp) {
  process.stdout.write(part.message.content)
}

How it fits into the AI ecosystem

  • Ollama itself is an open‑source platform for running LLMs locally and accessing hosted models. This library is the official JavaScript glue, enabling developers to integrate those models into web front‑ends, server‑side services, or full‑stack applications.
  • By mirroring the Ollama REST API, the library stays up‑to‑date with new endpoints (e.g., systemone) without requiring developers to hand‑craft HTTP calls.

Building / contributing

  • The project can be built from source with npm run build.
  • It follows a conventional TypeScript/JavaScript package layout, exposing both a default import (import ollama from 'ollama') and a named Ollama class for custom configuration.

All information above is taken directly from the repository’s README; no additional features have been inferred.

Related

  • Project
  • Dispatch
  • Project
  • Dispatch
  • Project