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
5 changes: 4 additions & 1 deletion packages/core/src/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { anthropic } from "./providers/anthropic.js";
import { baseten } from "./providers/baseten.js";
import { chutes } from "./providers/chutes.js";
import { cloudflareWorkersAi } from "./providers/cloudflare-workers-ai.js";
import { cortecs } from "./providers/cortecs.js";
import { crossmodel } from "./providers/crossmodel.js";
import { deepinfra } from "./providers/deepinfra.js";
import { digitalocean } from "./providers/digitalocean.js";
Expand Down Expand Up @@ -116,6 +117,7 @@ export const providers: {
baseten: SyncProvider<any>;
chutes: SyncProvider<any>;
"cloudflare-workers-ai": SyncProvider<any>;
cortecs: SyncProvider<any>;
crossmodel: SyncProvider<any>;
deepinfra: SyncProvider<any>;
digitalocean: SyncProvider<any>;
Expand Down Expand Up @@ -144,6 +146,7 @@ export const providers: {
baseten,
chutes,
"cloudflare-workers-ai": cloudflareWorkersAi,
cortecs,
crossmodel,
deepinfra,
digitalocean,
Expand Down Expand Up @@ -183,7 +186,7 @@ export const groups = {
"vercel",
],
cloudflare: ["cloudflare-workers-ai"],
direct: ["ambient", "anthropic", "baseten", "chutes", "deepinfra", "digitalocean", "google", "hyper", "openai", "ovhcloud", "pioneer", "tinfoil", "venice", "wandb", "xai"],
direct: ["ambient", "anthropic", "baseten", "chutes", "cortecs", "deepinfra", "digitalocean", "google", "hyper", "openai", "ovhcloud", "pioneer", "tinfoil", "venice", "wandb", "xai"],
} as const;

type ProviderID = keyof typeof providers;
Expand Down
169 changes: 169 additions & 0 deletions packages/core/src/sync/providers/cortecs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { z } from "zod";

import { describeModel } from "../../describe.js";
import type { ExistingModel, SyncProvider, SyncedFullModel, SyncedModel } from "../index.js";
import { factorBaseModel, resolveModelMetadataBaseModel } from "./openrouter.js";

const API_ENDPOINT = "https://api.cortecs.ai/v1/models";
const CANONICAL_BASE_MODEL_EXCEPTIONS = {
"claude-sonnet-4": "anthropic/claude-sonnet-4-0",
} as const;
// Cortecs publishes its default catalog prices in EUR per million tokens.
// Exchange rate used by the existing Cortecs entries, as of 2026-07-30.
const EUR_TO_USD = 1.114;

const CortecsModality = z.enum(["text", "audio", "image", "video", "pdf"]);

export const CortecsModel = z.object({
id: z.string().min(1),
created: z.number().int().nonnegative(),
description: z.string().optional(),
pricing: z.object({
currency: z.literal("EUR"),
input_token: z.number().nonnegative(),
output_token: z.number().nonnegative(),
cache_read_cost: z.number().nonnegative().optional(),
cache_write_cost: z.number().nonnegative().optional(),
}).passthrough(),
context_size: z.number().int().positive(),
input_modalities: z.array(CortecsModality).default(["text"]),
output_modalities: z.array(CortecsModality).default(["text"]),
supported_features: z.array(z.string()).default([]),
}).passthrough();

export const CortecsResponse = z.object({
object: z.literal("list"),
data: z.array(CortecsModel),
}).passthrough();

export type CortecsModel = z.infer<typeof CortecsModel>;

export const cortecs = {
id: "cortecs",
name: "Cortecs",
modelsDir: "providers/cortecs/models",
deleteMissing: true,
async fetchModels() {
const response = await fetch(API_ENDPOINT);
if (!response.ok) {
throw new Error(`Cortecs models request failed: ${response.status} ${response.statusText}`);
}
return response.json();
},
parseModels(raw) {
return CortecsResponse.parse(raw).data;
},
translateModel(model, context) {
return {
id: model.id,
model: buildCortecsModel(model, context.existing(model.id), context.authored(model.id)),
};
},
} satisfies SyncProvider<CortecsModel>;

function dateFromTimestamp(timestamp: number) {
return new Date(timestamp * 1_000).toISOString().slice(0, 10);
}

function usd(value: number | undefined) {
if (value === undefined) return undefined;
return Math.round(value * EUR_TO_USD * 1_000) / 1_000;
}

export function buildCortecsModel(
model: CortecsModel,
existing: ExistingModel | undefined,
authored: ExistingModel | undefined,
): SyncedModel {
const features = new Set(model.supported_features);
const input = model.input_modalities;
const output = model.output_modalities;
const canonical = existing?.base_model ?? resolveCortecsBaseModel(model.id);
const sourceReasoning = features.has("reasoning");
const reasoning = canonical === undefined ? sourceReasoning : existing?.reasoning ?? sourceReasoning;
const reasoningOptions = canonical === undefined
? (sourceReasoning ? existing?.reasoning_options ?? [] : undefined)
: (existing?.reasoning === true ? existing.reasoning_options : undefined);
const limit = {
context: model.context_size,
input: existing?.limit?.input,
output: authored?.limit?.output ?? model.context_size,
};
const cost = {
input: usd(model.pricing.input_token),
output: usd(model.pricing.output_token),
cache_read: usd(model.pricing.cache_read_cost) ?? existing?.cost?.cache_read,
cache_write: usd(model.pricing.cache_write_cost) ?? existing?.cost?.cache_write,
reasoning: existing?.cost?.reasoning,
tiers: existing?.cost?.tiers,
};
if (canonical !== undefined) {
return factorBaseModel(canonical, {
description: existing?.description,
attachment: input.some((value) => value !== "text"),
reasoning: undefined,
reasoning_options: reasoningOptions,
temperature: existing?.temperature,
tool_call: features.has("tools"),
structured_output: features.has("json_mode"),
status: existing?.status,
interleaved: existing?.interleaved,
limit,
modalities: { input, output },
cost,
}, limit, existing?.base_model_omit);
}

const family = existing?.family;
return {
name: existing?.name ?? model.id,
description: existing?.description ?? model.description ?? describeModel({
id: model.id,
name: model.id,
family,
reasoning,
tool_call: features.has("tools"),
structured_output: features.has("json_mode"),
open_weights: existing?.open_weights ?? false,
limit,
modalities: { input, output },
}),
family,
release_date: existing?.release_date ?? dateFromTimestamp(model.created),
last_updated: existing?.last_updated ?? dateFromTimestamp(model.created),
attachment: input.some((value) => value !== "text"),
reasoning,
reasoning_options: reasoningOptions,
temperature: existing?.temperature ?? false,
tool_call: features.has("tools"),
structured_output: features.has("json_mode"),
knowledge: existing?.knowledge,
open_weights: existing?.open_weights ?? false,
status: existing?.status,
interleaved: existing?.interleaved,
cost,
limit,
modalities: { input, output },
} satisfies SyncedFullModel;
}

function resolveCortecsBaseModel(modelID: string) {
const exception = CANONICAL_BASE_MODEL_EXCEPTIONS[
modelID as keyof typeof CANONICAL_BASE_MODEL_EXCEPTIONS
];
if (exception !== undefined) return resolveModelMetadataBaseModel(exception);

const trailingFamily = /^claude-(\d+)-(\d+)-(opus|sonnet|haiku)$/.exec(modelID);
if (trailingFamily !== null) {
const [, major, minor, family] = trailingFamily;
return resolveModelMetadataBaseModel(`anthropic/claude-${family}-${major}-${minor}`);
}

const compactFamily = /^claude-(opus|sonnet|haiku)(\d+)-(\d+)$/.exec(modelID);
if (compactFamily !== null) {
const [, family, major, minor] = compactFamily;
return resolveModelMetadataBaseModel(`anthropic/claude-${family}-${major}-${minor}`);
}

return resolveModelMetadataBaseModel(modelID);
}
22 changes: 22 additions & 0 deletions packages/core/test/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
parseAnthropicPricing,
type AnthropicModel,
} from "../src/sync/providers/anthropic.js";
import { buildCortecsModel, type CortecsModel } from "../src/sync/providers/cortecs.js";
import {
buildCrossModel,
type CrossModelModel,
Expand Down Expand Up @@ -2138,6 +2139,27 @@ test("defaults new reasoning models to empty reasoning options", () => {
});
});

test("preserves authored Cortecs reasoning options missing from the API", () => {
const model: CortecsModel = {
id: "deepseek-v4-flash-0731",
created: 1_775_088_000,
pricing: { currency: "EUR", input_token: 0.224, output_token: 0.269 },
context_size: 1_048_576,
input_modalities: ["text"],
output_modalities: ["text"],
supported_features: ["reasoning", "tools"],
};
const existing: ExistingModel = {
base_model: "deepseek/deepseek-v4-flash-0731",
reasoning: true,
reasoning_options: [{ type: "effort", values: ["low", "medium", "high"] }],
};

expect(buildCortecsModel(model, existing, existing)).toMatchObject({
reasoning_options: [{ type: "effort", values: ["low", "medium", "high"] }],
});
});

test("syncs OpenRouter reasoning efforts from model metadata", () => {
const model = buildOpenRouterModel(openRouterModel({
reasoning: {
Expand Down
23 changes: 23 additions & 0 deletions providers/cortecs/models/apertus-70b.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name = "apertus-70b"
description = "Apertus 70B is an open, multilingual language model designed for research, long-context reasoning, and sovereignty-focused AI systems."
release_date = "2026-07-08"
last_updated = "2026-07-08"
attachment = false
reasoning = true
temperature = false
tool_call = true
structured_output = false
open_weights = false
reasoning_options = []

[cost]
input = 1.393
output = 2.228

[limit]
context = 65_536
output = 65_536

[modalities]
input = ["text"]
output = ["text"]
33 changes: 14 additions & 19 deletions providers/cortecs/models/claude-4-5-sonnet.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
name = "Claude 4.5 Sonnet"
base_model = "anthropic/claude-sonnet-4-5"
description = "Balanced Claude model for coding, analysis, agent workflows, and cost control"
# Cortecs maps `reasoning_effort = low|medium|high` and
# `thinking.budget_tokens >= 1024`; unsupported fields may be silently ignored.
# https://api.cortecs.ai/v1/models (accessed 2026-06-25)
family = "claude-sonnet"
release_date = "2025-09-29"
last_updated = "2025-09-29"
knowledge = "2025-07-31"
attachment = true
reasoning = true
reasoning_options = [{ type = "effort", values = ["low", "medium", "high"] }, { type = "budget_tokens", min = 1_024 }]
tool_call = true
temperature = true
open_weights = false
structured_output = true

[[reasoning_options]]
type = "effort"
values = ["low", "medium", "high"]

[[reasoning_options]]
type = "budget_tokens"
min = 1_024

[cost]
input = 3.259
output = 16.296
input = 2.989
output = 14.945
cache_read = 0.326
cache_write = 4.078

[limit]
context = 200_000
output = 200_000

[modalities]
input = ["text", "image", "pdf"]
output = ["text"]
input = ["text", "image"]
34 changes: 15 additions & 19 deletions providers/cortecs/models/claude-4-6-sonnet.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
name = "Claude Sonnet 4.6"
base_model = "anthropic/claude-sonnet-4-6"
description = "Balanced Claude model for coding, analysis, agent workflows, and cost control"
# Cortecs maps `reasoning_effort = low|medium|high` and
# `thinking.budget_tokens >= 1024`; unsupported fields may be silently ignored.
# https://api.cortecs.ai/v1/models (accessed 2026-06-25)
family = "claude-sonnet"
release_date = "2026-02-17"
last_updated = "2026-03-13"
attachment = true
reasoning = true
reasoning_options = [{ type = "effort", values = ["low", "medium", "high"] }, { type = "budget_tokens", min = 1_024 }]
temperature = true
tool_call = true
knowledge = "2025-08-31"
open_weights = false
structured_output = true

[[reasoning_options]]
type = "effort"
values = ["low", "medium", "high"]

[[reasoning_options]]
type = "budget_tokens"
min = 1_024

[cost]
input = 3.59
output = 17.92
input = 3.196
output = 15.94
cache_read = 0.32
cache_write = 3.999

[limit]
context = 1_000_000
output = 1_000_000

[modalities]
input = ["text", "image", "pdf"]
output = ["text"]
input = ["text", "image"]
34 changes: 15 additions & 19 deletions providers/cortecs/models/claude-haiku-4-5.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
name = "Claude Haiku 4.5"
base_model = "anthropic/claude-haiku-4-5"
description = "Fast Claude model for responsive assistance, classification, and lightweight agents"
# Cortecs maps `reasoning_effort = low|medium|high` and
# `thinking.budget_tokens >= 1024`; unsupported fields may be silently ignored.
# https://api.cortecs.ai/v1/models (accessed 2026-06-25)
family = "claude-haiku"
release_date = "2025-10-15"
last_updated = "2025-10-15"
attachment = true
reasoning = true
reasoning_options = [{ type = "effort", values = ["low", "medium", "high"] }, { type = "budget_tokens", min = 1_024 }]
temperature = true
tool_call = true
knowledge = "2025-02-28"
open_weights = false
structured_output = true

[[reasoning_options]]
type = "effort"
values = ["low", "medium", "high"]

[[reasoning_options]]
type = "budget_tokens"
min = 1_024

[cost]
input = 1.09
output = 5.43
input = 0.996
output = 4.982
cache_read = 0.099
cache_write = 1.186

[limit]
context = 200_000
output = 200_000

[modalities]
input = ["text", "image", "pdf"]
output = ["text"]
input = ["text", "image"]
Loading
Loading