fix: use published Claude capacity when upstream metadata is missing
This commit is contained in:
@@ -3,3 +3,4 @@ export const CAPACITY_RANGES: Readonly<Record<'contextLimit' | 'maxOutputTokens'
|
||||
export function capacitySettings(input?: { contextLimit?: number; maxOutputTokens?: number }, previous?: { contextLimit?: number; maxOutputTokens?: number }): { contextLimit: number; maxOutputTokens: number };
|
||||
export function capacityMode(value?: string): 'model' | 'manual';
|
||||
export function messagesOutputSetting(config: { model?: string; nativeParameters?: Record<string, unknown>; maxOutputTokens?: number; upstreamModel?: { id: string; maxOutputTokens?: number | null } }): { value: unknown; source: string };
|
||||
export function modelCapacityDeclaration(config: { model?: string; upstreamModel?: { id: string; contextLimit?: number | null; maxOutputTokens?: number | null } }, field: 'contextLimit' | 'maxOutputTokens'): { value: number; source: 'upstream_catalog' | 'official_model_spec'; sourceUrl?: string; checkedAt?: string } | null;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { unrestricted } from './execution-policy.mjs';
|
||||
import { officialModelCapacity } from './official-model-capacity.mjs';
|
||||
|
||||
// Editable fallbacks for upstreams that do not publish capacity. These values
|
||||
// are not verified model capabilities or ceilings on larger models.
|
||||
@@ -16,12 +17,21 @@ export function capacitySettings(input = {}, previous = DEFAULT_MODEL_CAPACITY,
|
||||
|
||||
export const isPassthrough = config => config.capacityMode === 'passthrough';
|
||||
|
||||
export function modelCapacityDeclaration(config, field) {
|
||||
if (!['contextLimit', 'maxOutputTokens'].includes(field)) return null;
|
||||
const member = config.modelRouting?.members?.find(value => value.id === config.modelConnectionId) ?? config;
|
||||
const upstream = member.upstreamModel;
|
||||
if (upstream?.id === member.model && Number.isSafeInteger(upstream[field]) && upstream[field] > 0) return { value: upstream[field], source: 'upstream_catalog' };
|
||||
const official = officialModelCapacity(member.model);
|
||||
return official ? { value: official[field], source: official.source, sourceUrl: official.sourceUrl, checkedAt: official.checkedAt } : null;
|
||||
}
|
||||
|
||||
export function messagesOutputSetting(config) {
|
||||
const member = config.modelRouting?.members?.find(value => value.id === config.modelConnectionId) ?? config;
|
||||
const native = config.nativeParameters ?? member.nativeParameters ?? {};
|
||||
if (Object.hasOwn(native, 'max_tokens')) return { value: native.max_tokens, source: 'explicit_native' };
|
||||
const upstream = member.upstreamModel;
|
||||
if (upstream?.id === member.model && upstream.maxOutputTokens) return { value: upstream.maxOutputTokens, source: 'upstream_catalog' };
|
||||
const declaration = modelCapacityDeclaration(config, 'maxOutputTokens');
|
||||
if (declaration) return declaration;
|
||||
return { value: member.maxOutputTokens ?? config.maxOutputTokens ?? DEFAULT_MODEL_CAPACITY.maxOutputTokens, source: 'connection_declaration' };
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Exact pinned IDs from Anthropic's Models overview, checked 2026-11-06.
|
||||
// These are synchronous Messages declarations, not measured gateway limits.
|
||||
// The separate 300K Message Batches beta is not used for ordinary requests.
|
||||
const sourceUrl = 'https://platform.claude.com/docs/en/models/overview';
|
||||
const claude = Object.freeze(Object.fromEntries([
|
||||
'claude-fable-5-1', 'claude-opus-5-5', 'claude-sonnet-5-5', 'claude-haiku-5-5',
|
||||
].map(model => [model, Object.freeze({ model, contextLimit: 1000000, maxOutputTokens: 128000,
|
||||
sourceUrl, checkedAt: '2026-11-06', source: 'official_model_spec' })])));
|
||||
|
||||
export function officialModelCapacity(model) {
|
||||
return typeof model === 'string' && Object.hasOwn(claude, model) ? claude[model] : null;
|
||||
}
|
||||
Reference in New Issue
Block a user