{"data":{"slug":"ollama-ollama-js","name":"ollama-js","tagline":"Integrate JavaScript projects with Ollama using this TypeScript library","github_url":"https://github.com/ollama/ollama-js","owner":"ollama","repo":"ollama-js","owner_avatar_url":"https://avatars.githubusercontent.com/u/151674099?v=4","primary_language":"TypeScript","stars":4370,"forks":477,"topics":["javascript","js","ollama"],"archived":false,"github_pushed_at":"2026-02-18T22:06:18+00:00","maintenance_label":"Slowing","stars_delta_30d":30,"url":"https://www.graphcanon.com/tools/ollama-ollama-js","markdown_url":"https://www.graphcanon.com/tools/ollama-ollama-js.md","api_url":"https://www.graphcanon.com/api/graphcanon/tools/ollama-ollama-js","graph_url":"https://www.graphcanon.com/api/graphcanon/graph?tool=ollama-ollama-js","description":"Ollama JavaScript library","homepage_url":"https://ollama.com","license":"MIT","open_issues":92,"watchers":40,"ai_summary":"The Ollama JavaScript Library simplifies the integration of JavaScript and TypeScript projects with Ollama, allowing for easy interaction including usage in browsers and streaming responses.","readme_excerpt":"# Ollama JavaScript Library\n\nThe Ollama JavaScript library provides the easiest way to integrate your JavaScript project with [Ollama](https://github.com/jmorganca/ollama).\n\n## Getting Started\n\n```\nnpm i ollama\n```\n\n## Usage\n\n```javascript\nimport ollama from 'ollama'\n\nconst response = await ollama.chat({\n  model: 'llama3.1',\n  messages: [{ role: 'user', content: 'Why is the sky blue?' }],\n})\nconsole.log(response.message.content)\n```\n\n### Browser Usage\n\nTo use the library without node, import the browser module.\n\n```javascript\nimport ollama from 'ollama/browser'\n```\n\n## Streaming responses\n\nResponse streaming can be enabled by setting `stream: true`, modifying function calls to return an `AsyncGenerator` where each part is an object in the stream.\n\n```javascript\nimport ollama from 'ollama'\n\nconst message = { role: 'user', content: 'Why is the sky blue?' }\nconst response = await ollama.chat({\n  model: 'llama3.1',\n  messages: [message],\n  stream: true,\n})\nfor await (const part of response) {\n  process.stdout.write(part.message.content)\n}\n```\n\n## Cloud Models\n\nRun larger models by offloading to Ollama’s cloud while keeping your local workflow.\n\n[You can see models currently available on Ollama's cloud here.](https://ollama.com/search?c=cloud)\n\n### Run via local Ollama\n\n1) Sign in (one-time):\n\n```\nollama signin\n```\n\n2) Pull a cloud model:\n\n```\nollama pull gpt-oss:120b-cloud\n```\n\n3) Use as usual (offloads automatically):\n\n```javascript\nimport { Ollama } from 'ollama'\n\nconst ollama = new Ollama()\nconst response = await ollama.chat({\n  model: 'gpt-oss:120b-cloud',\n  messages: [{ role: 'user', content: 'Explain quantum computing' }],\n  stream: true,\n})\nfor await (const part of response) {\n  process.stdout.write(part.message.content)\n}\n```\n\n### Cloud API (ollama.com)\n\nAccess cloud models directly by pointing the client at `https://ollama.com`.\n\n1) Create an [API key](https://ollama.com/settings/keys), then set the `OLLAMA_API_KEY` environment variable:\n\n```\nexport OLLAMA_API_KEY=your_api_key\n```\n\n2) Generate a response via the cloud API:\n\n```javascript\nimport { Ollama } from 'ollama'\n\nconst ollama = new Ollama({\n  host: 'https://ollama.com',\n  headers: { Authorization: 'Bearer ' + process.env.OLLAMA_API_KEY },\n})\n\nconst response = await ollama.chat({\n  model: 'gpt-oss:120b',\n  messages: [{ role: 'user', content: 'Explain quantum computing' }],\n  stream: true,\n})\n\nfor await (const part of response) {\n  process.stdout.write(part.message.content)\n}\n```\n\n## API\n\nThe Ollama JavaScript library's API is designed around the [Ollama REST API](https://github.com/jmorganca/ollama/blob/main/docs/api.md)\n\n### chat\n\n```javascript\nollama.chat(request)\n```\n\n- `request` `<Object>`: The request object containing chat parameters.\n\n  - `model` `<string>` The name of the model to use for the chat.\n  - `messages` `<Message[]>`: Array of message objects representing the chat history.\n    - `role` `<string>`: The role of the message sender ('user', 'system', or 'assistant').\n    - `content` `<string>`: The content of the message.\n    - `images` `<Uint8Array[] | string[]>`: (Optional) Images to be included in the message, either as Uint8Array or base64 encoded strings.\n    - `tool_name` `<string>`: (Optional) Add the name of the tool that was executed to inform the model of the result \n  - `format` `<string>`: (Optional) Set the expected format of the response (`json`).\n  - `stream` `<boolean>`: (Optional) When true an `AsyncGenerator` is returned.\n  - `think` `<boolean | \"high\" | \"medium\" | \"low\">`: (Optional) Enable model thinking. Use `true`/`false` or specify a level. Requires model support.\n  - `logprobs` `<boolean>`: (Optional) Return log probabilities for tokens. Requires model support.\n  - `top_logprobs` `<number>`: (Optional) Number of top log probabilities to return per token when `logprobs` is enabled.\n  - `keep_alive` `<string | number>`: (Optional) How long to keep the model loaded. A number (seconds) or a string with a duration unit suffix (\"300ms","github_created_at":"2023-09-13T22:58:51+00:00","created_at":"2026-07-15T11:04:00.20246+00:00","updated_at":"2026-09-20T05:13:30.378715+00:00","categories":[{"slug":"inference-serving","name":"Inference & Serving","url":"https://www.graphcanon.com/categories/inference-serving","markdown_url":"https://www.graphcanon.com/categories/inference-serving.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/inference-serving"}],"tags":[{"slug":"javascript","name":"javascript"},{"slug":"typescript","name":"typescript"}],"trust":{"provenance":{"is_fork":false,"github_id":691303110,"owner_type":"Organization","methodology":"github_public_v1","parent_repo":null,"near_duplicate_slugs":[]},"computed_at":"2026-09-20T05:13:28.465Z","maintenance":{"label":"Slowing","score":36,"methodology":"github_public_v1","releases_90d":0,"days_since_push":213,"last_release_at":"2025-11-13T23:02:40Z","stars_delta_30d":30,"open_issues_delta_30d":8},"security_summary":{"status":"findings","scanner":"osv@v1","low_count":9,"high_count":0,"last_scan_at":"2026-07-15T11:04:03.054Z","medium_count":0,"scan_profile":"deps","critical_count":0}},"capability_facts":{"mcp":{"source":"repo_scan","observed_at":"2026-09-20T05:13:29.458Z","server_manifest":false},"scan":{"source":"repo_scan","observed_at":"2026-09-20T05:13:29.458Z"},"languages":{"value":["typescript","javascript"],"source":"github.language+package.json","observed_at":"2026-09-20T05:13:29.458Z"},"license_spdx":{"value":"MIT","source":"github.license","observed_at":"2026-09-20T05:13:29.458Z"}},"decision_facts":{"hosting":null,"pricing":{"model":"freemium","summary":"The ollama-js library is free to download and integrate into your project under the MIT License, though using cloud models may require API key setup and adherence to Ollama's pricing for cloud usage."},"requirements":{"notes":["- This library requires Node.js if not used in a browser context.","- For access to Ollama's cloud models, set up the necessary credentials as per their documentation."],"requires_docker":false},"constraints":{"pricing_model":"freemium","requires_docker":false},"when_to_use":["Use ollama-js when you need to integrate your JavaScript or TypeScript project with Ollama models for chat functionality.","Choose this library if your application has a requirement for streaming chat responses, which can enhance user interaction in real-time scenarios."],"when_not_to_use":["Avoid using ollama-js if your project requires complex image handling beyond base64 encoding or Uint8Array formats.","Do not use this library if you are restricted to environments where node modules cannot be used and browser-specific imports are also not feasible."],"source":"enrich:decision_facts","observed_at":"2026-07-17T09:06:42.004Z"},"constraint_facets":{"pricing_model":"freemium","requires_docker":false},"decision_summary":[{"label":"Pricing","value":"freemium - The ollama-js library is free to download and integrate into your project under the MIT License, though using cloud models may require API key setup and adherence to Ollama's pricing for cloud usage."},{"label":"Requirements","value":"- This library requires Node.js if not used in a browser context.; - For access to Ollama's cloud models, set up the necessary credentials as per their documentation."},{"label":"Adopt for","value":"ollama-js simplifies interactions with Ollama models in JavaScript and TypeScript projects, offering support for browser usage and streaming responses."}]}}