{"_id":"1xai-sdk","name":"1xai-sdk","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"1xai-sdk","version":"0.1.0","description":"Thin, drop-in SDK for the 1xAi gateway (https://1xai.ir) — OpenAI, Claude, Gemini and DeepSeek from inside Iran, billed in Toman.","keywords":["1xai","1xai.ir","openai","anthropic","claude","gemini","deepseek","llm","ai","iran","persian","farsi","toman","gateway","openai-compatible","proxy"],"homepage":"https://1xai.ir","repository":{"type":"git","url":"git+https://github.com/codedpro/1xai-sdk.git","directory":"node"},"bugs":{"url":"https://github.com/codedpro/1xai-sdk/issues"},"license":"MIT","author":{"name":"1xAi","email":"support@1xai.ir","url":"https://1xai.ir"},"type":"module","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/esm/index.d.ts","bin":{"onexai":"dist/esm/cli.js"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"},"default":"./dist/esm/index.js"},"./package.json":"./package.json"},"engines":{"node":">=18"},"scripts":{"build":"npm run clean && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/fixup.mjs","clean":"node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"","typecheck":"tsc -p tsconfig.esm.json --noEmit","test":"npm run build && node --test test/*.test.mjs","prepublishOnly":"npm run build && node --test test/*.test.mjs"},"dependencies":{"openai":">=4.60.0 <7"},"devDependencies":{"@types/node":"^22.10.2","typescript":"^5.7.2"},"publishConfig":{"access":"public"},"_id":"1xai-sdk@0.1.0","gitHead":"3f04755e76ce1027d7c5084b564756ac4f774327","_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-ndUyieDi5yaPyGkrO4FD7mIXugNsVLLFZRpmD8H3asBrJJbpmrByHCWsjd9hX2qhw6PR/9JagpXuz1YkQj9+Lg==","shasum":"d085bcb33c3ed9a1fa9cd3390c55ab85d6552374","tarball":"https://registry.npmjs.org/1xai-sdk/-/1xai-sdk-0.1.0.tgz","fileCount":73,"unpackedSize":289204,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD0RlGuAEc62hT1TUVO6r9E9M2xQTNhVL+UAYSk17pL0AIhAPSsbun8ZlV3MH0NH7uZuJVj4/oH4be5/+wuebtmtCZz"}]},"_npmUser":{"name":"codedpro","email":"dev.codedpro@gmail.com"},"directories":{},"maintainers":[{"name":"codedpro","email":"dev.codedpro@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/1xai-sdk_0.1.0_1785082634903_0.5235587232016101"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-26T16:17:14.709Z","0.1.0":"2026-07-26T16:17:15.074Z","modified":"2026-07-26T16:17:15.287Z"},"maintainers":[{"name":"codedpro","email":"dev.codedpro@gmail.com"}],"description":"Thin, drop-in SDK for the 1xAi gateway (https://1xai.ir) — OpenAI, Claude, Gemini and DeepSeek from inside Iran, billed in Toman.","homepage":"https://1xai.ir","keywords":["1xai","1xai.ir","openai","anthropic","claude","gemini","deepseek","llm","ai","iran","persian","farsi","toman","gateway","openai-compatible","proxy"],"repository":{"type":"git","url":"git+https://github.com/codedpro/1xai-sdk.git","directory":"node"},"author":{"name":"1xAi","email":"support@1xai.ir","url":"https://1xai.ir"},"bugs":{"url":"https://github.com/codedpro/1xai-sdk/issues"},"license":"MIT","readme":"# onexai — Node/TypeScript SDK for the 1xAi gateway\n\n[1xAi](https://1xai.ir) is an OpenAI-compatible AI gateway for Iran: one key and one\nbase URL for OpenAI, Anthropic Claude, Google Gemini and DeepSeek — no VPN, no\nforeign card, billed in Toman.\n\n```bash\nnpm install 1xai-sdk\n```\n\n```ts\nimport { OneXAI, costOfResponse, formatCost } from \"1xai-sdk\";\n\nconst client = new OneXAI(); // reads ONEXAI_API_KEY, falls back to OPENAI_API_KEY\n\nconst reply = await client.chat.completions.create({\n  model: \"gpt-4o-mini\",\n  messages: [{ role: \"user\", content: \"سلام! یک جوک فارسی بگو\" }],\n});\n\nconsole.log(reply.choices[0].message.content);\nconsole.log(formatCost(costOfResponse(reply))); // -> 102 Toman (gpt-4o-mini, 14in/23out)\n```\n\nShips ESM + CommonJS + type declarations. Node >= 18.\n\n## Why this package is thin (and why that is the point)\n\n1xAi's whole claim is that it **is** the OpenAI API at a different base URL. So this\npackage does not re-implement an SDK — `OneXAI` extends the official `openai` client\nand pre-configures it. Writing our own HTTP, streaming, retry and tool-call layer\nwould mean shipping a worse copy of a client OpenAI already maintains, and it would\ndrift every time the API gains a field.\n\nYou do not strictly need this package:\n\n```ts\nimport OpenAI from \"openai\";\nconst client = new OpenAI({ apiKey: \"1xai-...\", baseURL: \"https://1xai.ir/v1\" });\n```\n\nThat is the entire integration. What `onexai` adds is the small set of things the\ngeneric SDK cannot know about a gateway in Iran:\n\n| | |\n|---|---|\n| **Toman cost** | `estimateCost()` / `costOfResponse()` priced from 1xAi's public catalogue |\n| **Real errors** | the gateway answers in Persian; `explain()` turns that into one actionable English sentence — including `402`, which here means *your wallet is empty*, not *your code is broken* |\n| **Key validation** | pasting an `sk-...` key throws at construction instead of a confusing 401 later |\n| **Native passthroughs** | `anthropicConfig()` and `geminiConfig()` for prompt caching, thinking budgets and `cachedContents` |\n| **`npx onexai doctor`** | one command that tells you which of key / network / credit / upstream is actually broken |\n\n## CLI\n\n```bash\nnpx onexai doctor                        # diagnose key, connectivity, credit, upstream health\nnpx onexai price gpt-4o-mini 1000 500    # Toman cost of a call\nnpx onexai models --provider anthropic   # what you can call, with prices\nnpx onexai status                        # live upstream health, as seen from Iran\n```\n\n## Cost estimation\n\nPrices come from `https://1xai.ir/api/models` — public, no key required. A snapshot\nships with the package so the helper works offline; call `fetchPricing()` for live\nprices.\n\n```ts\nimport { estimateCost, fetchPricing } from \"1xai-sdk\";\n\nestimateCost(\"claude-opus-4-5\", 50_000, 2_000).totalToman; // 67068\nestimateCost(\"gpt-4o-mini\", 1000, 500, await fetchPricing()).totalToman;\n```\n\nAudio and image endpoints are billed per second and per image, so they are **not** in\nthe token catalogue. `estimateCost(\"whisper-1\", ...)` throws `UnknownModelError`\nexplaining that, rather than quietly returning zero.\n\n## Model routing\n\nYou never choose a provider — the model name does it. `claude-*` → Anthropic,\n`gemini-*`/`gemma-*` → Google, `deepseek-*` → DeepSeek, everything else → OpenAI.\n\n```ts\nimport { routeProvider } from \"1xai-sdk\";\nrouteProvider(\"claude-opus-4-5\"); // \"anthropic\"\n```\n\n## Full cookbook\n\nRunnable recipes for Cursor, Continue, Cline, Open WebUI, n8n, streaming, Persian\nWhisper transcription, image generation and cost control live in the\n[repository README](https://github.com/codedpro/1xai-sdk).\n\n## License\n\nMIT. Community-maintained; not an official 1xAi product unless the 1xAi team adopts it.\n","readmeFilename":"README.md","_rev":"1-4bef990023f261e9450f2e90c85bd336"}