{"_id":"@apitreedev/sdk","name":"@apitreedev/sdk","dist-tags":{"latest":"0.3.1"},"versions":{"0.3.1":{"name":"@apitreedev/sdk","version":"0.3.1","description":"apitree SDK — One token, 1,700+ APIs. TypeScript/JavaScript client for the apitree API Marketplace. 26 methods including streaming, health/stats, fine-tuning, BYOK.","type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"build":"tsc","typecheck":"tsc --noEmit","prepublishOnly":"pnpm build","publish:npm":"npm publish --access public"},"keywords":["apitree","api","marketplace","sdk","mcp","ai-agent","api-gateway","batch-api"],"license":"MIT","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/ApitreeDev/nexus.git","directory":"packages/sdk"},"devDependencies":{"@apitree/tsconfig":"workspace:*","typescript":"^5.5.0"},"gitHead":"1e688eb7c5fdfd76df714cbb27b68c9fbb801627","_id":"@apitreedev/sdk@0.3.1","bugs":{"url":"https://github.com/ApitreeDev/nexus/issues"},"homepage":"https://github.com/ApitreeDev/nexus#readme","_nodeVersion":"25.5.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-+/Xl86xN38HTh/LHElfGnsYKaRTaTx4x/00f8JduGaxIj3cYnO4EkIz/+4Ekcx9/ivAFPZFgLfKCqkYb52df1A==","shasum":"063b3c931741528ffb6ebedbcc11c21b09cb61c0","tarball":"https://registry.npmjs.org/@apitreedev/sdk/-/sdk-0.3.1.tgz","fileCount":6,"unpackedSize":69477,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDcya9sgTPo+Rv+tj44HTd3xn2/msWTMc72DQAzPtc4pQIhAIL+vkWbGA0tIpoCpOsyuNRFqSr0gq8yk2UgA2NlMNr/"}]},"_npmUser":{"name":"apitree-dev","email":"dev@apitree.ai"},"directories":{},"maintainers":[{"name":"apitree-dev","email":"dev@apitree.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_0.3.1_1783997310710_0.6314758544582624"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-14T02:48:30.542Z","0.3.1":"2026-07-14T02:48:30.862Z","modified":"2026-07-14T02:48:31.097Z"},"maintainers":[{"name":"apitree-dev","email":"dev@apitree.ai"}],"description":"apitree SDK — One token, 1,700+ APIs. TypeScript/JavaScript client for the apitree API Marketplace. 26 methods including streaming, health/stats, fine-tuning, BYOK.","homepage":"https://github.com/ApitreeDev/nexus#readme","keywords":["apitree","api","marketplace","sdk","mcp","ai-agent","api-gateway","batch-api"],"repository":{"type":"git","url":"git+https://github.com/ApitreeDev/nexus.git","directory":"packages/sdk"},"bugs":{"url":"https://github.com/ApitreeDev/nexus/issues"},"license":"MIT","readme":"# @apitreedev/sdk\n\nOfficial TypeScript/JavaScript SDK for [apitree](https://apitree.ai) — the AI-Native API Marketplace.\n\nOne token, 1,400+ APIs. Call any API in 3 lines of code.\n\n## Installation\n\n```bash\nnpm install @apitreedev/sdk\n```\n\n## Quick Start\n\n```typescript\nimport { ApitreeClient } from '@apitreedev/sdk';\n\nconst apitree = new ApitreeClient('nxs_live_YOUR_KEY');\nconst result = await apitree.call('exchange-rates');\nconsole.log(result.data);\n```\n\n## Methods\n\n### `call(apiSlug, params?, options?)`\n\nCall any API through the apitree proxy.\n\n```typescript\n// GET request\nconst weather = await apitree.call('open-meteo-weather', { latitude: 37.5, longitude: 127 });\n\n// POST request\nconst result = await apitree.call('openai-chat', { prompt: 'Hello' }, { method: 'POST' });\n\n// With sub-path\nconst post = await apitree.call('jsonplaceholder-posts', undefined, { path: '1' });\n```\n\n### `batch(calls)`\n\nCall up to 10 APIs concurrently.\n\n```typescript\nconst results = await apitree.batch([\n  { api: 'exchange-rates' },\n  { api: 'restcountries', path: 'all' },\n  { api: 'open-meteo-weather', params: { latitude: 37.5, longitude: 127 } },\n]);\n\nconsole.log(results.meta.total_latency_ms); // Total wall time\nconsole.log(results.results); // Array of responses\n```\n\n### `search(intent, options?)`\n\nSearch APIs by natural language.\n\n```typescript\nconst apis = await apitree.search('weather data');\nconst financial = await apitree.search('exchange rates', { category: 'financial', limit: 5 });\n```\n\n### `getApi(slug)`\n\nGet API details including endpoints and MCP tool definition.\n\n```typescript\nconst details = await apitree.getApi('exchange-rates');\nconsole.log(details.endpoints);\nconsole.log(details.mcp_tool);\n```\n\n### `getUsage()`\n\nGet usage overview — calls, credits, plan info.\n\n```typescript\nconst usage = await apitree.getUsage();\nconsole.log(usage.usage_30d.total_calls);\nconsole.log(usage.subscription?.credits_remaining);\n```\n\n### `getCredits()`\n\nGet current credit balance.\n\n```typescript\nconst { balance } = await apitree.getCredits();\n```\n\n### `exportUsage(options?)`\n\nExport usage logs as CSV or JSONL (alias: NDJSON).\n\n```typescript\nconst csv = await apitree.exportUsage({ format: 'csv', days: 7 });\nconst jsonl = await apitree.exportUsage({ format: 'jsonl', days: 30 });\n```\n\n### `compare(slugs)`\n\nCompare 2–5 APIs side-by-side. Useful when picking between alternatives (OpenAI vs. Anthropic, etc.). Returns price, SLA, and 30-day latency/error stats.\n\n```typescript\nconst { comparison } = await apitree.compare(['openai-chat', 'anthropic-messages']);\nfor (const api of comparison) {\n  console.log(`${api.name}: $${api.pricePerCall}/call, p95 ${api.stats.p95_latency_ms}ms`);\n}\n```\n\n### `trendingByTag(tag, opts?)`\n\nTrending APIs for a single tag — e.g. `\"weather\"`, `\"llm\"`, `\"payments\"`. Ranks by 30-day usage and subscriber count by default; pass `sort: \"recent\"` to rank by creation date instead.\n\n```typescript\nconst { apis } = await apitree.trendingByTag('llm', { limit: 5 });\nfor (const api of apis) {\n  console.log(`${api.name} — ${api.calls30d.toLocaleString()} calls (30d)`);\n}\n\n// Recency-sorted\nconst { apis: newest } = await apitree.trendingByTag('weather', { sort: 'recent', limit: 3 });\n```\n\n### `getKeyQuota(keyId)` / `setKeyQuota(keyId, dailyCap)`\n\nPer-API-key daily quota — cap individual keys independently of your tier limit. Pass `null` as the cap to remove it.\n\n```typescript\n// Cap a scraper key at 1,000 calls/day\nawait apitree.setKeyQuota('key_abc', 1_000);\n\n// Check remaining\nconst quota = await apitree.getKeyQuota('key_abc');\nconsole.log(`${quota.daily_used} / ${quota.daily_cap} used today`);\n\n// Remove the cap\nawait apitree.setKeyQuota('key_abc', null);\n```\n\n### `getTrainingStats()` (admin)\n\nGet fine-tuning pipeline statistics: ready interactions, quality distribution, freshness.\n\n```typescript\nconst stats = await apitree.getTrainingStats();\nconsole.log(stats.readyForTraining); // 142\nconsole.log(stats.freshness.last7d); // 89\n```\n\n### `buildTrainingDataset(options?)` (admin)\n\nBuild a validated, PII-scrubbed training dataset in JSONL format.\n\n```typescript\nconst dataset = await apitree.buildTrainingDataset({\n  minQuality: 4,\n  scrubPii: true,\n  includeHumanEdits: true,\n});\nconsole.log(dataset.version.count); // 142 examples\nconsole.log(dataset.validation.valid); // true\n```\n\n### `submitHumanEdit(interactionId, correctedOutput, qualityOverride?)` (admin)\n\nSubmit a human-corrected ground truth for fine-tuning.\n\n```typescript\nawait apitree.submitHumanEdit('interaction-uuid', { corrected: 'data' }, 5);\n```\n\n### `markTrained(ids)` (admin)\n\nMark interactions as used for training to prevent re-export.\n\n```typescript\nawait apitree.markTrained(['id1', 'id2', 'id3']);\n```\n\n### `getApiStatus(slug)`\n\nGet real-time health status for a single API (30min + 24h stats).\n\n```typescript\nconst status = await apitree.getApiStatus('open-meteo-forecast');\nconsole.log(status.status);                    // \"operational\"\nconsole.log(status.last_30min.error_rate_pct); // 0.5\nconsole.log(status.last_30min.p95_latency_ms); // 234\n```\n\n### `stream(apiSlug, params?, options?)`\n\nStream responses from LLM APIs (SSE/chunked). Returns a `ReadableStream`.\n\n```typescript\nconst stream = await apitree.stream('openai-chat', { messages: [{ role: 'user', content: 'Hello' }] });\n\nconst reader = stream.getReader();\nconst decoder = new TextDecoder();\nwhile (true) {\n  const { done, value } = await reader.read();\n  if (done) break;\n  process.stdout.write(decoder.decode(value));\n}\n```\n\n### `getForecast()`\n\nCredit burn rate forecast with depletion date, trend, and cache savings.\n\n```typescript\nconst forecast = await apitree.getForecast();\nconsole.log(forecast.burnRatePerDay);         // 42.5 credits/day\nconsole.log(forecast.daysRemaining);          // 23\nconsole.log(forecast.projectedDepletionDate); // \"2026-05-05\"\nconsole.log(forecast.trend);                  // \"steady\"\nconsole.log(forecast.cacheSavingsPerDay);     // 12.3 credits/day saved by cache\n```\n\n## Error Handling\n\n```typescript\nimport { ApitreeClient, NexusError } from '@apitreedev/sdk';\n\ntry {\n  await apitree.call('some-api');\n} catch (err) {\n  if (err instanceof NexusError) {\n    console.log(err.status);  // 429, 402, 502, etc.\n    console.log(err.message); // Human-readable error\n  }\n}\n```\n\n## Response Format\n\nEvery API call returns:\n\n```typescript\n{\n  data: any,        // Provider response data\n  meta: {\n    cached: boolean,\n    latency_ms: number,\n    credits_used: number,\n    request_id: string,\n    provider: string,\n    status_code: number,\n  }\n}\n```\n\n## Configuration\n\n```typescript\nconst apitree = new ApitreeClient('nxs_live_xxx', {\n  baseUrl: 'https://apitree.ai', // default\n  timeout: 30000, // 30s default\n});\n```\n\n## Get a Token\n\nSign up at [apitree.ai/signup](https://apitree.ai/signup) — free, no credit card required.\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-12c516ab41389c56af49440902e80eed"}