Skip to content

Quick Start

Get started with aimatey in less than 5 minutes. This guide will walk you through creating your first bridge and making AI requests.

Terminal window
npm install @johnhenry/aimatey-core @johnhenry/aimatey-frontend @johnhenry/aimatey-backend

You’ll need an API key from at least one provider. We recommend starting with Anthropic (Claude) as it’s reliable and has good free tier:

Terminal window
# Sign up at https://console.anthropic.com/
# Get your API key and set it in your environment
export ANTHROPIC_API_KEY=sk-ant-...

Alternatively, use any of these providers:

Create a file called hello.ts:

import { Bridge } from '@johnhenry/aimatey-core';
import { OpenAIFrontendAdapter } from '@johnhenry/aimatey-frontend/openai';
import { AnthropicBackendAdapter } from '@johnhenry/aimatey-backend/anthropic';
// Create a bridge: OpenAI format → Anthropic execution
const bridge = new Bridge(
new OpenAIFrontendAdapter(),
new AnthropicBackendAdapter({
apiKey: process.env.ANTHROPIC_API_KEY
})
);
// Make a request using OpenAI format
const response = await bridge.chat({
model: 'gpt-4', // Will be mapped to claude-opus-5
messages: [
{ role: 'user', content: 'What is aimatey?' }
]
});
console.log(response.choices[0].message.content);
Terminal window
npx tsx hello.ts

You should see Claude’s response, even though you wrote the code in OpenAI format!

Your Code (OpenAI format)
↓
OpenAI Frontend Adapter (parses OpenAI format)
↓
Intermediate Representation (IR) - Universal format
↓
Anthropic Backend Adapter (converts IR to Anthropic format)
↓
Claude API (executes the request)
↓
Response (converted back through the pipeline)

This is the power of aimatey: write once, run anywhere.

For simple use cases, use backends directly:

import { AnthropicBackendAdapter } from '@johnhenry/aimatey-backend/anthropic';
const backend = new AnthropicBackendAdapter({
apiKey: process.env.ANTHROPIC_API_KEY
});
// Execute using Intermediate Representation (IR) format.
// In IR the model lives under `parameters`, and `metadata` is required.
const response = await backend.execute({
messages: [
{ role: 'user', content: 'Hello!' }
],
parameters: {
model: 'claude-haiku-4-5-20251001'
},
metadata: {
requestId: crypto.randomUUID(),
timestamp: Date.now()
}
});
// An IR response has a single `message` - there is no `choices` array
console.log(response.message.content);

Stream responses in real-time:

const stream = bridge.chatStream({
model: 'gpt-4',
messages: [
{ role: 'user', content: 'Write a haiku about TypeScript' }
],
stream: true
});
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta?.content;
if (delta) {
process.stdout.write(delta);
}
}

Pattern 3: Multiple Providers with Fallback

Section titled “Pattern 3: Multiple Providers with Fallback”

Route to multiple providers with automatic fallback:

import { Bridge, createRouter } from '@johnhenry/aimatey-core';
import { OpenAIFrontendAdapter } from '@johnhenry/aimatey-frontend/openai';
import { OpenAIBackendAdapter } from '@johnhenry/aimatey-backend/openai';
import { AnthropicBackendAdapter } from '@johnhenry/aimatey-backend/anthropic';
const router = createRouter({
routingStrategy: 'fallback'
})
.register('openai', new OpenAIBackendAdapter({
apiKey: process.env.OPENAI_API_KEY
}))
.register('anthropic', new AnthropicBackendAdapter({
apiKey: process.env.ANTHROPIC_API_KEY
}))
.setFallbackChain(['openai', 'anthropic']); // Try OpenAI first, fall back to Anthropic
const bridge = new Bridge(
new OpenAIFrontendAdapter(),
router
);
// If OpenAI fails, automatically tries Anthropic
const response = await bridge.chat({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }]
});

Add logging, caching, or retry logic:

import { Bridge } from '@johnhenry/aimatey-core';
import { OpenAIFrontendAdapter } from '@johnhenry/aimatey-frontend/openai';
import { AnthropicBackendAdapter } from '@johnhenry/aimatey-backend/anthropic';
import { createLoggingMiddleware, createRetryMiddleware } from '@johnhenry/aimatey-middleware';
const bridge = new Bridge(
new OpenAIFrontendAdapter(),
new AnthropicBackendAdapter({ apiKey: process.env.ANTHROPIC_API_KEY }),
[
createLoggingMiddleware({ level: 'info' }),
createRetryMiddleware({ maxAttempts: 3 })
]
);
// Now all requests are logged and automatically retried on failure
const response = await bridge.chat({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }]
});

The beauty of aimatey is that switching providers is trivial. Just change the backend:

// Development: Use local Ollama
const devBackend = new OllamaBackendAdapter({
baseURL: 'http://localhost:11434'
});
// Production: Use OpenAI
const prodBackend = new OpenAIBackendAdapter({
apiKey: process.env.OPENAI_API_KEY
});
// Choose based on environment
const backend = process.env.NODE_ENV === 'production'
? prodBackend
: devBackend;
const bridge = new Bridge(
new OpenAIFrontendAdapter(),
backend
);
// Same code works with both!
const response = await bridge.chat({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }]
});

You can also swap the frontend to use different API formats:

import { AnthropicFrontendAdapter } from '@johnhenry/aimatey-frontend/anthropic';
import { OpenAIBackendAdapter } from '@johnhenry/aimatey-backend/openai';
// Accept Anthropic format → Execute on OpenAI
const bridge = new Bridge(
new AnthropicFrontendAdapter(),
new OpenAIBackendAdapter({ apiKey: process.env.OPENAI_API_KEY })
);
// Now use Anthropic's API format
const response = await bridge.chat({
model: 'claude-haiku-4-5-20251001',
max_tokens: 100,
messages: [
{ role: 'user', content: 'Hello!' }
]
});
Error: Missing required API key

Solution: Set your API key in the environment:

Terminal window
export ANTHROPIC_API_KEY=sk-ant-...

Or load from a .env file using dotenv:

Terminal window
npm install dotenv
import 'dotenv/config';
Cannot find module '@johnhenry/aimatey-core'

Solution: Make sure you’ve installed all required packages:

Terminal window
npm install @johnhenry/aimatey-core @johnhenry/aimatey-frontend @johnhenry/aimatey-backend

By default, models are automatically mapped between providers:

  • gpt-4 → claude-opus-5 (OpenAI → Anthropic)
  • gpt-3.5-turbo → claude-haiku-4-5-20251001 (OpenAI → Anthropic)

To use specific models, check the Backend Adapters documentation.


Ready to build? Continue to Core Concepts to learn the fundamentals, or jump straight to Your First Bridge for a hands-on tutorial!