Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/examples/nodejs/multi-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ async function main() {
// Anthropic: Mid-tier
if (process.env.ANTHROPIC_API_KEY) {
models.push({
name: 'claude-3-haiku-20240307',
name: 'claude-haiku-4-5',
provider: 'anthropic',
cost: 0.00075,
cost: 0.001,
qualityThreshold: 0.85,
apiKey: process.env.ANTHROPIC_API_KEY,
});
Expand Down
22 changes: 11 additions & 11 deletions packages/core/examples/nodejs/production-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ async function example1_ErrorHandling() {

const agent = new CascadeAgent({
models: [
{ name: 'claude-3-5-haiku-20241022', provider: 'anthropic', cost: 0.0008 },
{ name: 'gpt-5', provider: 'openai', cost: 0.00125 },
{ name: 'claude-haiku-4-5', provider: 'anthropic', cost: 0.001 },
{ name: 'claude-sonnet-4-5', provider: 'anthropic', cost: 0.003 },
],
});

Expand Down Expand Up @@ -106,8 +106,8 @@ async function example2_Caching() {

const agent = new CascadeAgent({
models: [
{ name: 'claude-3-5-haiku-20241022', provider: 'anthropic', cost: 0.0008 },
{ name: 'gpt-5', provider: 'openai', cost: 0.00125 },
{ name: 'claude-haiku-4-5', provider: 'anthropic', cost: 0.001 },
{ name: 'claude-sonnet-4-5', provider: 'anthropic', cost: 0.003 },
],
});

Expand Down Expand Up @@ -246,8 +246,8 @@ async function example4_CostTracking() {

const agent = new CascadeAgent({
models: [
{ name: 'claude-3-5-haiku-20241022', provider: 'anthropic', cost: 0.0008 },
{ name: 'gpt-5', provider: 'openai', cost: 0.00125 },
{ name: 'claude-haiku-4-5', provider: 'anthropic', cost: 0.001 },
{ name: 'claude-sonnet-4-5', provider: 'anthropic', cost: 0.003 },
],
});

Expand Down Expand Up @@ -314,8 +314,8 @@ async function example5_Monitoring() {

const agent = new CascadeAgent({
models: [
{ name: 'claude-3-5-haiku-20241022', provider: 'anthropic', cost: 0.0008 },
{ name: 'gpt-5', provider: 'openai', cost: 0.00125 },
{ name: 'claude-haiku-4-5', provider: 'anthropic', cost: 0.001 },
{ name: 'claude-sonnet-4-5', provider: 'anthropic', cost: 0.003 },
],
});

Expand Down Expand Up @@ -343,15 +343,15 @@ async function example6_Failover() {
// Primary cascade
const primaryAgent = new CascadeAgent({
models: [
{ name: 'claude-3-5-haiku-20241022', provider: 'anthropic', cost: 0.0008 },
{ name: 'gpt-5', provider: 'openai', cost: 0.00125 },
{ name: 'claude-haiku-4-5', provider: 'anthropic', cost: 0.001 },
{ name: 'claude-sonnet-4-5', provider: 'anthropic', cost: 0.003 },
],
});

// Fallback cascade (different providers)
const fallbackAgent = new CascadeAgent({
models: [
{ name: 'llama-3.1-8b-instant', provider: 'groq', cost: 0.00005 },
{ name: 'llama-4-scout', provider: 'groq', cost: 0.00011 },
{ name: 'gpt-4o-mini', provider: 'openai', cost: 0.00015 },
],
});
Expand Down
34 changes: 18 additions & 16 deletions packages/core/examples/nodejs/reasoning-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
*
* cascadeflow supports reasoning models from 4 providers with automatic detection:
*
* 1. OpenAI (o1, o1-mini, o3-mini)
* 1. OpenAI (o3, o4-mini)
* - Chain-of-thought reasoning with hidden thinking
* - reasoning_effort parameter (low/medium/high)
* - max_completion_tokens required
* - o3 and o4-mini are the latest reasoning models (2025)
*
* 2. Anthropic (claude-3-7-sonnet-20250219)
* 2. Anthropic (claude-sonnet-4-5, claude-opus-4-1)
* - Extended thinking mode (enable with thinkingBudget)
* - Minimum 1024 tokens thinking budget
* - Visible reasoning in response
* - Claude Sonnet 4.5 and Opus 4.1 released in 2025
*
* 3. Ollama (deepseek-r1, deepseek-r1-distill)
* - Free local inference
Expand All @@ -29,12 +31,12 @@
import { CascadeAgent } from '../../src/index';

async function reasoningModelsExample() {
// Example 1: o1-mini (supports streaming, no tools, no system messages)
console.log('\n=== Example 1: o1-mini (original reasoning model) ===');
// Example 1: o4-mini (latest fast reasoning model)
console.log('\n=== Example 1: o4-mini (latest reasoning model) ===');
const agent1 = new CascadeAgent({
models: [
{
name: 'o1-mini', // Auto-detected as reasoning model
name: 'o4-mini', // Auto-detected as reasoning model
provider: 'openai',
},
],
Expand All @@ -55,12 +57,12 @@ async function reasoningModelsExample() {
});
console.log('Cost:', `$${result1.cost.toFixed(6)}`);

// Example 2: o1-2024-12-17 (newer model with reasoning_effort)
console.log('\n=== Example 2: o1-2024-12-17 with reasoning_effort ===');
// Example 2: o3 (latest advanced reasoning model with reasoning_effort)
console.log('\n=== Example 2: o3 with reasoning_effort ===');
const agent2 = new CascadeAgent({
models: [
{
name: 'o1-2024-12-17',
name: 'o3',
provider: 'openai',
},
],
Expand Down Expand Up @@ -89,7 +91,7 @@ async function reasoningModelsExample() {
provider: 'openai',
},
{
name: 'o1-mini', // Falls back to reasoning model if needed
name: 'o4-mini', // Falls back to reasoning model if needed
provider: 'openai',
},
],
Expand Down Expand Up @@ -128,12 +130,12 @@ async function reasoningModelsExample() {
console.log(' Response length:', result.content.length, 'chars');
}

// Example 5: Anthropic Claude 3.7 Sonnet with Extended Thinking
console.log('\n=== Example 5: Claude 3.7 Sonnet (Extended Thinking) ===');
// Example 5: Anthropic Claude Sonnet 4.5 with Extended Thinking
console.log('\n=== Example 5: Claude Sonnet 4.5 (Extended Thinking) ===');
const agent4 = new CascadeAgent({
models: [
{
name: 'claude-3-7-sonnet-20250219',
name: 'claude-sonnet-4-5',
provider: 'anthropic',
},
],
Expand Down Expand Up @@ -229,11 +231,11 @@ async function reasoningModelsExample() {
cost: 0, // Free local inference
},
{
name: 'o1-mini',
name: 'o4-mini',
provider: 'openai',
},
{
name: 'claude-3-7-sonnet-20250219',
name: 'claude-sonnet-4-5',
provider: 'anthropic',
},
],
Expand All @@ -242,8 +244,8 @@ async function reasoningModelsExample() {

console.log('This cascade tries:');
console.log(' 1. DeepSeek-R1 (local, free)');
console.log(' 2. Falls back to o1-mini if quality < 0.85');
console.log(' 3. Falls back to Claude 3.7 as final option');
console.log(' 2. Falls back to o4-mini if quality < 0.85');
console.log(' 3. Falls back to Claude Sonnet 4.5 as final option');
console.log();
console.log('Perfect for cost optimization with reasoning models!');
}
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ function getQualityConfig(mode: QualityMode = 'balanced') {
export const PRESET_BEST_OVERALL: { models: ModelConfig[] } = {
models: [
{
name: 'claude-3-5-haiku-20241022',
name: 'claude-haiku-4-5',
provider: 'anthropic',
cost: 0.0008,
cost: 0.001,
},
{
name: 'gpt-4o-mini',
Expand Down Expand Up @@ -220,14 +220,14 @@ export const PRESET_OPENAI_ONLY: { models: ModelConfig[] } = {
export const PRESET_ANTHROPIC_ONLY: { models: ModelConfig[] } = {
models: [
{
name: 'claude-3-5-haiku-20241022',
name: 'claude-haiku-4-5',
provider: 'anthropic',
cost: 0.0008,
cost: 0.001,
},
{
name: 'claude-sonnet-4-5-20250929',
name: 'claude-sonnet-4-5',
provider: 'anthropic',
cost: 0.009,
cost: 0.003,
},
],
};
Expand Down Expand Up @@ -319,16 +319,16 @@ export function createPreset(config: PresetConfig = {}): {
cost: 0.00015,
});
models.push({
name: 'claude-3-5-haiku-20241022',
name: 'claude-haiku-4-5',
provider: 'anthropic',
cost: 0.0008,
cost: 0.001,
});
} else {
// Balanced - mix of speed and reliability
models.push({
name: 'claude-3-5-haiku-20241022',
name: 'claude-haiku-4-5',
provider: 'anthropic',
cost: 0.0008,
cost: 0.001,
});
models.push({
name: 'gpt-4o-mini',
Expand Down
35 changes: 32 additions & 3 deletions packages/core/src/providers/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ const OPENAI_PRICING: Record<string, { input: number; output: number }> = {
'gpt-4o-2024-08-06': { input: 0.0025, output: 0.010 },
'gpt-4o-2024-05-13': { input: 0.005, output: 0.015 },

// O1 series (reasoning models)
// O1 series (reasoning models - previous generation)
'o1-preview': { input: 0.015, output: 0.060 },
'o1-mini': { input: 0.003, output: 0.012 },
'o1': { input: 0.015, output: 0.060 }, // o1-2024-12-17
'o1-2024-12-17': { input: 0.015, output: 0.060 },

// O3 series (reasoning models - future)
// O3 series (reasoning models - released April 2025)
'o3': { input: 0.010, output: 0.040 },
'o3-mini': { input: 0.001, output: 0.005 },

// O4 series (reasoning models - latest, optimized for speed and cost)
'o4-mini': { input: 0.0008, output: 0.004 },

// GPT-4 series (previous generation)
'gpt-4-turbo': { input: 0.010, output: 0.030 },
'gpt-4-turbo-2024-04-09': { input: 0.010, output: 0.030 },
Expand Down Expand Up @@ -103,7 +107,7 @@ export function getReasoningModelInfo(modelName: string): ReasoningModelInfo {
};
}

// O3-mini (future reasoning model)
// O3 series (released April 2025)
if (name.includes('o3-mini')) {
return {
isReasoning: true,
Expand All @@ -116,6 +120,31 @@ export function getReasoningModelInfo(modelName: string): ReasoningModelInfo {
};
}

if (name === 'o3' || name.startsWith('o3-')) {
return {
isReasoning: true,
provider: 'openai',
supportsStreaming: true,
supportsTools: true,
supportsSystemMessages: false,
supportsReasoningEffort: true,
requiresMaxCompletionTokens: true,
};
}

// O4 series (latest reasoning models)
if (name.includes('o4-mini') || name.includes('o4')) {
return {
isReasoning: true,
provider: 'openai',
supportsStreaming: true,
supportsTools: true,
supportsSystemMessages: false,
supportsReasoningEffort: true,
requiresMaxCompletionTokens: true,
};
}

// Not a reasoning model
return {
isReasoning: false,
Expand Down
Loading
Loading