{"id":40339303,"url":"https://github.com/c41m50n/ai","last_synced_at":"2026-01-20T09:00:39.654Z","repository":{"id":333375232,"uuid":"1137078739","full_name":"C41M50N/ai","owner":"C41M50N","description":"Type-safe AI client with model registry, lazy providers, and optional cost tracking","archived":false,"fork":false,"pushed_at":"2026-01-20T07:01:29.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-20T07:26:27.183Z","etag":null,"topics":["ai","ai-sdk","devtools","llm","typescript","vercel"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@cbuff/ai","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/C41M50N.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2026-01-18T21:47:06.000Z","updated_at":"2026-01-20T07:01:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/C41M50N/ai","commit_stats":null,"previous_names":["c41m50n/llm","c41m50n/ai"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/C41M50N/ai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/C41M50N%2Fai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/C41M50N%2Fai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/C41M50N%2Fai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/C41M50N%2Fai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/C41M50N","download_url":"https://codeload.github.com/C41M50N/ai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/C41M50N%2Fai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28599827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T08:51:33.170Z","status":"ssl_error","status_checked_at":"2026-01-20T08:51:10.855Z","response_time":117,"last_error":"SSL_read: 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","ai-sdk","devtools","llm","typescript","vercel"],"created_at":"2026-01-20T09:00:18.703Z","updated_at":"2026-01-20T09:00:39.642Z","avatar_url":"https://github.com/C41M50N.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Type-safe AI client with model registry, lazy providers, and optional cost tracking—powered by [Vercel AI SDK](https://sdk.vercel.ai/)\n\n## Installation\n\n```bash\nbun add @cbuff/ai ai\n```\n\nInstall the provider SDKs you need:\n\n```bash\nbun add @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google\n```\n\n## Usage\n\n```typescript\nimport { createAI } from \"@cbuff/ai\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\n\nconst ai = createAI({\n  providers: {\n    openai: () =\u003e createOpenAI({ apiKey: process.env.OPENAI_API_KEY }),\n    anthropic: async () =\u003e {\n      const { createAnthropic } = await import(\"@ai-sdk/anthropic\");\n      return createAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY });\n    },\n  },\n  models: {\n    fast: { provider: \"openai\", id: \"gpt-4o-mini\" },\n    smart: { provider: \"openai\", id: \"gpt-4o\", costs: { input: 2.5, output: 10 } },\n    claude: { provider: \"anthropic\", id: \"claude-sonnet-4-20250514\", costs: { input: 3, output: 15 } },\n  },\n});\n\n// Full autocomplete on model names\nconst { data, metadata } = await ai.generate({\n  model: \"fast\",\n  prompt: \"Hello, world!\",\n});\n\nconsole.log(data);\nconsole.log(metadata.totalCostUsd); // undefined if costs not configured\n```\n\n## Features\n\n- **Type-safe model selection** — Full autocomplete on model aliases, provider references validated at compile time\n- **Lazy provider loading** — Providers can be sync or async, loaded on first use and cached\n- **Optional cost tracking** — Define `costs: { input, output }` per model (USD per 1M tokens), skip if you don't need it\n- **Unified config** — Single `createAI()` call with providers and models in one object\n\n## Why not use Vercel's AI SDK directly?\n\nVercel's SDK is a great foundation, but this wrapper solves the gaps that show up once you use it across multiple models and providers:\n\n- **Model registry with autocomplete** — Define named model aliases once and get compile-time safety everywhere you call `ai.generate`.\n- **Lazy provider wiring** — Configure providers as sync or async factories so you only load SDKs when you actually need them.\n- **Built-in cost tracking** — Attach per-model USD rates and get cost metadata back without extra bookkeeping.\n- **One config surface** — Providers, models, and defaults live together instead of being stitched across call sites.\n\n## API\n\n### `createAI(config)`\n\nCreates a typed AI client.\n\n```typescript\nconst ai = createAI({\n  providers: {\n    [key: string]: () =\u003e Provider | Promise\u003cProvider\u003e\n  },\n  models: {\n    [alias: string]: {\n      provider: string;  // must match a key in providers\n      id: string;        // provider model ID (typed per provider)\n      costs?: { input: number; output: number };  // USD per 1M tokens\n    }\n  }\n});\n```\n\n### `ai.generate(params)`\n\nGenerate text or structured output.\n\n```typescript\nconst { data, metadata } = await ai.generate({\n  model: \"fast\",           // required, autocompletes to your model aliases\n  prompt: \"Hello\",         // required\n  system: \"Be helpful\",    // optional\n  temperature: 0.7,        // optional\n  maxOutputTokens: 1000,   // optional\n  output: schema,          // optional, for structured output\n  logKey: \"my-request\",    // optional, logs timing and cost\n});\n```\n\n**Returns:**\n\n```typescript\n{\n  data: string | T,  // text or structured output\n  metadata: {\n    responseTimeMs: number,\n    inputTokens: number,\n    outputTokens: number,\n    inputCostUsd?: number,   // undefined if costs not configured\n    outputCostUsd?: number,\n    totalCostUsd?: number,\n  }\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc41m50n%2Fai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc41m50n%2Fai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc41m50n%2Fai/lists"}