co-mono/packages/ai
Mario Zechner d61d09b88d fix(ai): Deduplicate models and add Anthropic aliases
- Add proper Anthropic model aliases (claude-opus-4-1, claude-sonnet-4-0, etc.)
- Deduplicate models when same ID appears in both models.dev and OpenRouter
- models.dev takes priority over OpenRouter for duplicate IDs
- Fix test to use correct claude-3-5-haiku-latest alias
- Reduces Anthropic models from 11 to 10 (removed duplicate)
2025-08-29 23:34:01 +02:00
..
docs feat(ai): Add auto-generated TypeScript models with factory function 2025-08-25 21:31:29 +02:00
scripts fix(ai): Deduplicate models and add Anthropic aliases 2025-08-29 23:34:01 +02:00
src fix(ai): Deduplicate models and add Anthropic aliases 2025-08-29 23:34:01 +02:00
test fix(ai): Deduplicate models and add Anthropic aliases 2025-08-29 23:34:01 +02:00
package.json refactor(ai): Implement unified model system with type-safe createLLM 2025-08-29 23:19:47 +02:00
README.md refactor(ai): Implement unified model system with type-safe createLLM 2025-08-29 23:19:47 +02:00
tsconfig.build.json feat(ai): Create unified AI package with OpenAI, Anthropic, and Gemini support 2025-08-17 20:18:45 +02:00
vitest.config.ts feat(ai): Migrate tests to Vitest and add provider test coverage 2025-08-29 21:32:45 +02:00

@mariozechner/ai

Unified API for OpenAI, Anthropic, and Google Gemini LLM providers with streaming, tool calling, and thinking support.

Installation

npm install @mariozechner/ai

Quick Start

import { AnthropicLLM } from '@mariozechner/ai/providers/anthropic';
import { OpenAICompletionsLLM } from '@mariozechner/ai/providers/openai-completions';
import { GoogleLLM } from '@mariozechner/ai/providers/gemini';

// Pick your provider - same API for all
const llm = new AnthropicLLM('claude-sonnet-4-0');
// const llm = new OpenAICompletionsLLM('gpt-5-mini');
// const llm = new GoogleLLM('gemini-2.5-flash');

// Basic completion
const response = await llm.complete({
  messages: [{ role: 'user', content: 'Hello!' }]
});
console.log(response.content);

// Streaming with thinking
const streamResponse = await llm.complete({
  messages: [{ role: 'user', content: 'Explain quantum computing' }]
}, {
  onText: (chunk) => process.stdout.write(chunk),
  onThinking: (chunk) => process.stderr.write(chunk),
  // Provider specific config
  thinking: { enabled: true }
});

// Tool calling
const tools = [{
  name: 'calculator',
  description: 'Perform calculations',
  parameters: {
    type: 'object',
    properties: {
      expression: { type: 'string' }
    },
    required: ['expression']
  }
}];

const toolResponse = await llm.complete({
  messages: [{ role: 'user', content: 'What is 15 * 27?' }],
  tools
});

if (toolResponse.toolCalls) {
  for (const call of toolResponse.toolCalls) {
    console.log(`Tool: ${call.name}, Args:`, call.arguments);
  }
}

Development

This package is part of the pi monorepo. See the main README for development instructions.

License

MIT