{"_id":"@byteflyo-agent/sdk","_rev":"4-35f2d0356b1115d7b52ef3ab7393c0f1","name":"@byteflyo-agent/sdk","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"@byteflyo-agent/sdk","version":"1.0.0","keywords":["agent-api","anthropic","sdk","typescript","sse"],"license":"MIT","_id":"@byteflyo-agent/sdk@1.0.0","maintainers":[{"name":"iamshimanto","email":"shimanto.dev.bd@gmail.com"}],"dist":{"shasum":"55cc7977b12e1bb7fb5556c8f2c7d8aeb67f8df2","tarball":"https://registry.npmjs.org/@byteflyo-agent/sdk/-/sdk-1.0.0.tgz","fileCount":20,"integrity":"sha512-tT1l19wVC38g777pL75C7Yzfo6/ivtrzEQV6qiJ0IpURq+R7lSqi1Qlp+ajSZrXdqnWJ4Iu360mu4ZeEMwGWtQ==","signatures":[{"sig":"MEUCIDQMdrYpiDUIuo+TMutaua0NcYfbRGFLwMqKuDpIIqayAiEApWeQydbtSCkbd/BvH98qmLzfL/nRpYWuf7RDpbj2tkA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35403},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=20.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"cb358ab5c557f3a47816b820994f176cab8d3a3a","scripts":{"test":"node --import tsx --test test/unit.test.ts test/conformance.test.ts","build":"npm run clean && tsc -p tsconfig.json","check":"npm run typecheck && npm test && npm run build","clean":"node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"","typecheck":"tsc -p tsconfig.test.json","prepublishOnly":"npm run check"},"_npmUser":{"name":"iamshimanto","email":"shimanto.dev.bd@gmail.com"},"_npmVersion":"11.6.2","description":"Zero-dependency TypeScript/JavaScript SDK for the Agent API Anthropic-compatible contract","directories":{},"sideEffects":false,"_nodeVersion":"25.3.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.20.5","typescript":"^5.9.2","@types/node":"^24.3.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk_1.0.0_1787602771043_0.38650476459882244","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@byteflyo-agent/sdk","version":"1.0.1","keywords":["agent-api","anthropic","sdk","typescript","sse"],"license":"MIT","_id":"@byteflyo-agent/sdk@1.0.1","maintainers":[{"name":"iamshimanto","email":"shimanto.dev.bd@gmail.com"}],"dist":{"shasum":"a669f1385c369e5c064c1fe785d42dea22b92e4e","tarball":"https://registry.npmjs.org/@byteflyo-agent/sdk/-/sdk-1.0.1.tgz","fileCount":20,"integrity":"sha512-euxGo0+IyXYscuvdNunqxeZ7M/87WQx0CTI9XTQndX960zi07sv4hM+HOoZvT1I6ZlzR5oL7BYbdgXCI7mrqYA==","signatures":[{"sig":"MEUCIGkiWsF8VvvjBEgALoMCKtMQOfyQTvDY8jfCIPu1ievYAiEAr4mOqIbxZd4flpqziPgORWKb7ZO8fGqE577qQw3vATc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35403},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=20.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"cb358ab5c557f3a47816b820994f176cab8d3a3a","scripts":{"test":"node --import tsx --test test/unit.test.ts test/conformance.test.ts","build":"npm run clean && tsc -p tsconfig.json","check":"npm run typecheck && npm test && npm run build","clean":"node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"","typecheck":"tsc -p tsconfig.test.json","prepublishOnly":"npm run check"},"_npmUser":{"name":"iamshimanto","email":"shimanto.dev.bd@gmail.com"},"_npmVersion":"11.6.2","description":"Zero-dependency TypeScript/JavaScript SDK for the Agent API Anthropic-compatible contract","directories":{},"sideEffects":false,"_nodeVersion":"25.3.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.20.5","typescript":"^5.9.2","@types/node":"^24.3.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk_1.0.1_1787603072109_0.6751701807948127","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@byteflyo-agent/sdk","version":"1.1.0","keywords":["agent-api","anthropic","sdk","typescript","sse"],"license":"MIT","_id":"@byteflyo-agent/sdk@1.1.0","maintainers":[{"name":"iamshimanto","email":"shimanto.dev.bd@gmail.com"}],"dist":{"shasum":"11837e476d9939db52c32baa1926fbc00af4e8a6","tarball":"https://registry.npmjs.org/@byteflyo-agent/sdk/-/sdk-1.1.0.tgz","fileCount":20,"integrity":"sha512-7f2BoYDBIjjYq5bvJrhBso/7YWlaEN+9sRwiP5rYwn2CrNOwe02d9Dq9tN/g+041Qtg0zPbR86EAR8ZJDHSkZg==","signatures":[{"sig":"MEYCIQDOlvpbvzmUbnlXks1vAc9/nBeCLAtmvbOvdoH7SZCvfwIhAIL/BXrRRqjUmX9mXUOjCTLFw2JjykvyYy5GZEedE4wI","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35382},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=20.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"168211139d5e98124c36ebc603b01cfe0ec81f2a","scripts":{"test":"node --import tsx --test test/unit.test.ts test/conformance.test.ts","build":"npm run clean && tsc -p tsconfig.json","check":"npm run typecheck && npm test && npm run build","clean":"node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"","typecheck":"tsc -p tsconfig.test.json","prepublishOnly":"npm run check"},"_npmUser":{"name":"iamshimanto","email":"shimanto.dev.bd@gmail.com"},"_npmVersion":"11.6.2","description":"Zero-dependency TypeScript/JavaScript SDK for the Agent API Anthropic-compatible contract","directories":{},"sideEffects":false,"_nodeVersion":"25.3.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.20.5","typescript":"^5.9.2","@types/node":"^24.3.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk_1.1.0_1787753831801_0.449050935415511","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@byteflyo-agent/sdk","version":"1.1.1","description":"Zero-dependency TypeScript/JavaScript SDK for the Agent API Anthropic-compatible contract","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"sideEffects":false,"scripts":{"clean":"node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"","build":"npm run clean && tsc -p tsconfig.json","typecheck":"tsc -p tsconfig.test.json","test":"node --import tsx --test test/unit.test.ts test/conformance.test.ts","check":"npm run typecheck && npm test && npm run build","prepublishOnly":"npm run check"},"keywords":["agent-api","anthropic","sdk","typescript","sse"],"license":"MIT","engines":{"node":">=20.0.0"},"publishConfig":{"access":"public"},"devDependencies":{"@types/node":"^24.3.0","tsx":"^4.20.5","typescript":"^5.9.2"},"gitHead":"168211139d5e98124c36ebc603b01cfe0ec81f2a","_id":"@byteflyo-agent/sdk@1.1.1","_nodeVersion":"25.3.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-kZyOSSdJTEbYSo3OiOjDuRxHV8NdTO9pxIzJG6AuM5vNyJImoSTR0F0VHnhVy4YYcCvb4so229fl045SwiG3oA==","shasum":"ba9d79aa9ae2cff839278267a68382ea6ce52bf0","tarball":"https://registry.npmjs.org/@byteflyo-agent/sdk/-/sdk-1.1.1.tgz","fileCount":20,"unpackedSize":36354,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDNMuqf2yBbOfM4hHqKoRP/9apCvcEl3tHY0eUxaVmTIAIgapMEk1xXNG98bPLjKS74Otq8QfltJqy43OERePXYmaQ="}]},"_npmUser":{"name":"iamshimanto","email":"shimanto.dev.bd@gmail.com"},"directories":{},"maintainers":[{"name":"iamshimanto","email":"shimanto.dev.bd@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_1.1.1_1787754093129_0.5918926401419244"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-24T20:19:30.866Z","modified":"2026-08-26T14:21:33.490Z","1.0.0":"2026-08-24T20:19:31.188Z","1.0.1":"2026-08-24T20:24:32.261Z","1.1.0":"2026-08-26T14:17:11.970Z","1.1.1":"2026-08-26T14:21:33.260Z"},"license":"MIT","keywords":["agent-api","anthropic","sdk","typescript","sse"],"description":"Zero-dependency TypeScript/JavaScript SDK for the Agent API Anthropic-compatible contract","maintainers":[{"name":"iamshimanto","email":"shimanto.dev.bd@gmail.com"}],"readme":"# Agent API TypeScript SDK\n\n[![npm version](https://img.shields.io/npm/v/@byteflyo-agent/sdk.svg)](https://www.npmjs.com/package/@byteflyo-agent/sdk)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nOfficial, zero-runtime-dependency TypeScript/JavaScript client for the [Byteflyo Agent API](https://aiagent-backend.byteflyo.com).\n\nThis SDK implements the stable customer subset of the Anthropic-compatible OpenAPI contract. It provides fully-typed models, messages, Server-Sent Events (SSE) streaming, cooperative cancellation, timeouts, and bounded retries.\n\n- **Fast & Lightweight:** Zero external runtime dependencies. Built on native `fetch` and Web Streams.\n- **Secure:** Completely prevents logging of API keys, request content, and raw HTTP response bodies.\n- **Isomorphic:** Runs in Node.js 20+, Edge environments, and the browser.\n\n---\n\n## 📦 Install\n\n```sh\nnpm install @byteflyo-agent/sdk\n```\n\n## 🚀 Quick Start\n\n```ts\nimport { AgentApi, apiKey } from \"@byteflyo-agent/sdk\";\n\n// 1. Initialize the client\nconst client = new AgentApi({\n  apiKey: apiKey(process.env.API_KEY!),\n  // baseUrl defaults to https://aiagent-backend.byteflyo.com\n});\n\n// 2. Discover available models\nconst models = await client.listModels();\nconsole.log(\"Using model:\", models.items[0]?.name);\n\n// 3. Send a message\nconst response = await client.sendMessage({\n  model: models.items[0]!.name,\n  max_tokens: 256,\n  messages: [{ role: \"user\", content: \"Hello, world!\" }],\n});\n\nconsole.log(response.content);\n```\n\n---\n\n## ⚡ Streaming\n\nThe SDK supports parsing Anthropic-compatible Server-Sent Events (SSE).\n\n`streamMessage()` returns an iterable stream and also supports an `onEvent` callback. Iteration automatically handles backpressure.\n\n```ts\nconst abortController = new AbortController();\n\nconst stream = client.streamMessage(\n  {\n    model: \"claude-opus-5\",\n    max_tokens: 128,\n    messages: [{ role: \"user\", content: \"Write a poem about the sea.\" }],\n  },\n  {\n    signal: abortController.signal, // For cancellation\n  },\n);\n\nfor await (const event of stream) {\n  if (\n    event.type === \"content_block_delta\" &&\n    event.delta.type === \"text_delta\"\n  ) {\n    process.stdout.write(event.delta.text);\n  }\n\n  if (event.type === \"message_stop\") {\n    break;\n  }\n}\n```\n\n---\n\n## 🛡️ Reliability & Errors\n\n### Bounded Retries\n\nTo ensure idempotent safety and prevent accidental double-billing, **message POST requests and active streams are never automatically retried**.\n\nHowever, safe requests like `GET /v1/account/models` will automatically retry on transient network failures, timeouts, and HTTP status codes `408`, `429`, `500`, `502`, `503`, and `504`. Retries use capped exponential backoff and respect HTTP `Retry-After` headers.\n\nYou can configure retry limits (default `2`, max `5`):\n\n```ts\nconst client = new AgentApi({\n  apiKey: apiKey(\"...\"),\n  maxRetries: 3,\n  timeoutMs: 30_000,\n});\n```\n\n### Typed Error Handling\n\nAll errors thrown by the SDK are structured and extend from native `Error`:\n\n- `AgentApiError`: Server returned a structured HTTP API error (e.g., Auth, Rate Limit). Contains `status`, `type`, `code`, and `requestId`.\n- `AgentApiStreamError`: Stream cleanly parsed a terminal error event sent from the server mid-generation.\n- `AgentApiTimeoutError`: Request exceeded `timeoutMs`.\n- `AgentApiConnectionError`: Network failure, DNS issue, or unparseable JSON/SSE.\n\n---\n\n## 🔗 Links\n\n- **Documentation:** [TypeScript SDK API Reference](docs/API.md)\n- **Examples:** [`examples/`](examples)\n- **Source Code:** [GitHub Repository](https://github.com/example/agent-api)\n\n_(Note: Replace the GitHub URL above with your actual repository URL before finalizing)._\n","readmeFilename":"README.md"}