{"id":21966400,"url":"https://github.com/moeru-ai/xsai","last_synced_at":"2026-01-18T14:17:10.205Z","repository":{"id":263988184,"uuid":"891872929","full_name":"moeru-ai/xsai","owner":"moeru-ai","description":"🤖💬 extra-small AI SDK.","archived":false,"fork":false,"pushed_at":"2025-12-30T08:41:24.000Z","size":2287,"stargazers_count":546,"open_issues_count":6,"forks_count":43,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-01-01T02:53:39.424Z","etag":null,"topics":["ai","ollama","openai","typescript","xsai"],"latest_commit_sha":null,"homepage":"https://xsai.js.org","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moeru-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"kwaa"}},"created_at":"2024-11-21T05:25:02.000Z","updated_at":"2025-12-31T19:37:38.000Z","dependencies_parsed_at":"2025-01-15T09:26:19.324Z","dependency_job_id":"c6841e63-ffb3-4312-942a-7a2fcc96c1b7","html_url":"https://github.com/moeru-ai/xsai","commit_stats":null,"previous_names":["moeru-ai/xsai"],"tags_count":84,"template":false,"template_full_name":null,"purl":"pkg:github/moeru-ai/xsai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moeru-ai%2Fxsai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moeru-ai%2Fxsai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moeru-ai%2Fxsai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moeru-ai%2Fxsai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moeru-ai","download_url":"https://codeload.github.com/moeru-ai/xsai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moeru-ai%2Fxsai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28537492,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T13:04:05.990Z","status":"ssl_error","status_checked_at":"2026-01-18T13:01:44.092Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ollama","openai","typescript","xsai"],"created_at":"2024-11-29T13:15:54.492Z","updated_at":"2026-01-18T14:17:10.162Z","avatar_url":"https://github.com/moeru-ai.png","language":"TypeScript","funding_links":["https://github.com/sponsors/kwaa"],"categories":["Openai","TypeScript"],"sub_categories":[],"readme":"# xsAI\n\nextra-small AI SDK.\n\n\u003c!-- automd:badges name=\"xsai\" provider=\"badgen\" color=\"gray\" license bundlephobia packagephobia --\u003e\n\n[![npm version](https://flat.badgen.net/npm/v/xsai?color=gray)](https://npmjs.com/package/xsai)\n[![npm downloads](https://flat.badgen.net/npm/dm/xsai?color=gray)](https://npm.chart.dev/xsai)\n[![bundle size](https://flat.badgen.net/bundlephobia/minzip/xsai?color=gray)](https://bundlephobia.com/package/xsai)\n[![install size](https://flat.badgen.net/packagephobia/install/xsai?color=gray)](https://packagephobia.com/result?p=xsai)\n[![license](https://flat.badgen.net/github/license/moeru-ai/xsai?color=gray)](https://github.com/moeru-ai/xsai/blob/main/LICENSE)\n\n\u003c!-- /automd --\u003e\n\nxsAI is a series of utils to help you use OpenAI or OpenAI-compatible API.\n\n```ts\nimport { env } from 'node:process'\n\nimport { generateText } from '@xsai/generate-text'\n\nconst { text } = await generateText({\n  apiKey: env.OPENAI_API_KEY!,\n  baseURL: 'https://api.openai.com/v1/',\n  messages: [\n    {\n      content: 'You are a helpful assistant.',\n      role: 'system',\n    },\n    {\n      content: 'This is a test, so please answer \\'YES\\' and nothing else.',\n      role: 'user',\n    },\n  ],\n  model: 'gpt-4o',\n})\n\n// \"YES\"\nconsole.log(text)\n```\n\n## Features\n\n### \u003csmall\u003e\u003cruby\u003eextra\u003crp\u003e(\u003c/rp\u003e\u003crt\u003ex\u003c/rt\u003e\u003crp\u003e)\u003c/rp\u003e-small\u003crp\u003e(\u003c/rp\u003e\u003crt\u003es\u003c/rt\u003e\u003crp\u003e)\u003c/rp\u003e\u003c/ruby\u003e\u003c/small\u003e\n\nxsAI uses a variety of methods to make itself smaller.\n\nIt's just a wrapper for [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), ESM Only, adding additional dependencies only when absolutely necessary.\n\nHow xsAI small? you can try install it with [Packagephobia](https://packagephobia.com/result?p=xsai) or [Bundlephobia](https://bundlephobia.com/package/xsai):\n\n\u003e In the following table, we used packagephobia's install size and bundlephobia's minified/gzipped size.\n\n| Package | Install size | Bundled size | Gzipped size |\n|---|---|---|---|\n| xsai@0.4.0 | 142KB | 22.7KB | 7.1KB |\n| ai@6.0.11 | 5740KB | 301.5KB | 74.3KB |\n\nxsAI reduces the install size **40x** and the bundled size **13x**.\n\nNotably, this contains dependencies introduced to support tool calls and structured output.\n\nIf you only need the basic `generateText`, `@xsai/generate-text@0.4.0` is only 22.6KB install size and 4KB bundled size (1.7KB gzipped).\n\n### Runtime-agnostic\n\nxsAI doesn't depend on Node.js Built-in Modules, it works well in Browsers, Deno, Bun and even the Edge Runtime.\n\n## Usage\n\n### Install\n\n\u003e You can also install only some of the utils of xsAI, such as `@xsai/generate-text` and `@xsai/stream-text`.\n\n\u003c!-- automd:pm-install name=\"xsai\" auto=false --\u003e\n\n```sh\n# npm\nnpm install xsai\n\n# yarn\nyarn add xsai\n\n# pnpm\npnpm add xsai\n\n# bun\nbun install xsai\n\n# deno\ndeno install npm:xsai\n```\n\n\u003c!-- /automd --\u003e\n\n### Getting Started\n\nRead the [documentation](https://xsai.js.org/docs) to get started.\n\n### Examples\n\n###### Generating Text [(see above)](#xsai)\n\n###### Streaming Text\n\n```ts\nimport { env } from 'node:process'\n\nimport { streamText } from '@xsai/stream-text'\n\nconst { textStream } = streamText({\n  apiKey: env.OPENAI_API_KEY!,\n  baseURL: 'https://api.openai.com/v1/',\n  messages: [\n    {\n      content: 'You are a helpful assistant.',\n      role: 'system',\n    },\n    {\n      content: 'This is a test, so please answer \\'The quick brown fox jumps over the lazy dog.\\' and nothing else.',\n      role: 'user',\n    },\n  ],\n  model: 'gpt-4o',\n})\n\nconst text: string[] = []\n\nfor await (const textPart of textStream) {\n  text.push(textPart)\n}\n\n// \"The quick brown fox jumps over the lazy dog.\"\nconsole.log(text)\n```\n\n###### Generating Text w/ Tool Calling\n\n```ts\nimport { env } from 'node:process'\n\nimport { generateText } from '@xsai/generate-text'\nimport { tool } from '@xsai/tool'\nimport { description, object, pipe, string } from 'valibot'\n\nconst weather = await tool({\n  description: 'Get the weather in a location',\n  execute: ({ location }) =\u003e JSON.stringify({\n    location,\n    temperature: 42,\n  }),\n  name: 'weather',\n  parameters: object({\n    location: pipe(\n      string(),\n      description('The location to get the weather for'),\n    ),\n  }),\n})\n\nconst { text } = await generateText({\n  apiKey: env.OPENAI_API_KEY!,\n  baseURL: 'https://api.openai.com/v1/',\n  maxSteps: 2,\n  messages: [\n    {\n      content: 'You are a helpful assistant.',\n      role: 'system',\n    },\n    {\n      content: 'What is the weather in San Francisco? do not answer anything else.',\n      role: 'user',\n    },\n  ],\n  model: 'gpt-4o',\n  toolChoice: 'required',\n  tools: [weather],\n})\n\n// \"In San Francisco, it's currently 42°F.\"\nconsole.log(text)\n```\n\n#### Community Projects\n\n- [moeru-ai/airi](https://github.com/moeru-ai/airi)\n- [moeru-ai/arpk](https://github.com/moeru-ai/arpk)\n- [lingticio/neuri-js](https://github.com/lingticio/neuri-js)\n- [GramSearch/telegram-search](https://github.com/GramSearch/telegram-search)\n- [yusixian/moe-copy-ai](https://github.com/yusixian/moe-copy-ai)\n- [LemonNekoGH/flow-chat](https://github.com/LemonNekoGH/flow-chat)\n\n## License\n\n[MIT](LICENSE.md)\n\n## Sponsors\n\n![sponsors](https://github.com/kwaa/sponsors/blob/main/public/sponsors.svg?raw=true)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoeru-ai%2Fxsai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoeru-ai%2Fxsai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoeru-ai%2Fxsai/lists"}