{"data":{"slug":"ollama-ollama-js","name":"ollama-js","tagline":"Ollama JavaScript 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":4310,"forks":454,"topics":["javascript","js","ollama"],"archived":false,"github_pushed_at":"2026-02-18T22:06:18+00:00","maintenance_label":"Slowing","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":82,"watchers":37,"ai_summary":null,"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-07-15T11:04:05.149791+00:00","categories":[{"slug":"computer-vision","name":"Computer Vision","url":"https://www.graphcanon.com/categories/computer-vision","markdown_url":"https://www.graphcanon.com/categories/computer-vision.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/computer-vision"},{"slug":"developer-tools","name":"Developer Tools","url":"https://www.graphcanon.com/categories/developer-tools","markdown_url":"https://www.graphcanon.com/categories/developer-tools.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/developer-tools"},{"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":"js","name":"js"},{"slug":"ollama","name":"ollama"},{"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-07-15T11:04:02.410Z","maintenance":{"label":"Slowing","score":36,"methodology":"github_public_v1","releases_90d":0,"days_since_push":146,"last_release_at":"2025-11-13T23:02:40Z"},"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-07-15T11:04:02.109Z","server_manifest":false},"scan":{"source":"repo_scan","observed_at":"2026-07-15T11:04:02.109Z"},"languages":{"value":["typescript","javascript"],"source":"github.language+package.json","observed_at":"2026-07-15T11:04:02.109Z"},"license_spdx":{"value":"MIT","source":"github.license","observed_at":"2026-07-15T11:04:02.109Z"}}}}