YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(ai-gateway): backwards compat for old app @YYYYMMDD model IDs
Louis Beaumont5271f9043690
diff --git a/packages/ai-gateway/src/providers/anthropic-proxy.ts b/packages/ai-gateway/src/providers/anthropic-proxy.tsindex 3ffa882b1..ce7a57ee2 100644--- a/packages/ai-gateway/src/providers/anthropic-proxy.ts+++ b/packages/ai-gateway/src/providers/anthropic-proxy.ts@@ -36,6 +36,14 @@ export async function proxyToAnthropic([key: string]: any;};+ // Normalize Vertex-style @YYYYMMDD model IDs to Anthropic-style -YYYYMMDD+ // Old app versions send e.g. "claude-haiku-4-5@20251001" which Anthropic API won't accept+ if (body.model && body.model.includes('@')) {+ const original = body.model;+ body.model = body.model.replace('@', '-');+ console.log('proxyToAnthropic: normalized model', original, '->', body.model);+ }+console.log('proxyToAnthropic: model=', body.model, 'stream=', body.stream, 'messages count=', body.messages?.length);// Sanitize messages to fix common formatting issues (e.g. nested {text: {text: '...'}})diff --git a/packages/ai-gateway/src/providers/anthropic.ts b/packages/ai-gateway/src/providers/anthropic.tsindex 363a1757b..6b6511ed6 100644--- a/packages/ai-gateway/src/providers/anthropic.ts+++ b/packages/ai-gateway/src/providers/anthropic.ts@@ -50,12 +50,20 @@ export class AnthropicProvider implements AIProvider {return parts.length > 0 ? parts.join('\n\n') : undefined;}+ /**+ * Normalize model ID: convert Vertex @YYYYMMDD format to Anthropic -YYYYMMDD+ * Old app versions may send e.g. "claude-haiku-4-5@20251001"+ */+ private normalizeModel(model: string): string {+ return model.includes('@') ? model.replace('@', '-') : model;+ }+async createCompletion(body: RequestBody): Promise<Response> {const messages = this.formatMessages(body.messages);const response = await this.client.messages.create({messages,- model: body.model,+ model: this.normalizeModel(body.model),max_tokens: body.max_tokens || 4096,temperature: body.temperature,system: this.buildSystemPrompt(body),@@ -70,7 +78,7 @@ export class AnthropicProvider implements AIProvider {async createStreamingCompletion(body: RequestBody): Promise<ReadableStream> {const stream = await this.client.messages.create({messages: this.formatMessages(body.messages),- model: body.model,+ model: this.normalizeModel(body.model),stream: true,max_tokens: body.max_tokens || 4096,temperature: body.temperature,diff --git a/packages/ai-gateway/src/test/anthropic-proxy.unit.test.ts b/packages/ai-gateway/src/test/anthropic-proxy.unit.test.tsindex 51e588611..21e425459 100644--- a/packages/ai-gateway/src/test/anthropic-proxy.unit.test.ts+++ b/packages/ai-gateway/src/test/anthropic-proxy.unit.test.ts@@ -550,6 +550,87 @@ describe('Model ID format consistency', () => {});});+// ============================================================================+// Backwards compatibility: old app sends @YYYYMMDD model IDs+// ============================================================================+describe('Backwards compatibility with @YYYYMMDD model IDs', () => {+ const originalFetch = globalThis.fetch;++ afterEach(() => {+ globalThis.fetch = originalFetch;+ });++ it('proxyToAnthropic should normalize @ to - in model ID', async () => {+ let capturedBody: any = null;++ globalThis.fetch = async (_url: any, init: any) => {+ capturedBody = JSON.parse(init.body);+ return new Response(JSON.stringify({ type: 'message', content: [] }), { status: 200 });+ };++ const request = new Request('http://localhost/v1/messages', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({+ model: 'claude-haiku-4-5@20251001',+ max_tokens: 100,+ messages: [{ role: 'user', content: 'test' }],+ }),+ });++ await proxyToAnthropic(request, 'sk-ant-test-key');++ // The @ should be converted to - before sending to Anthropic API+ expect(capturedBody.model).toBe('claude-haiku-4-5-20251001');+ });++ it('proxyToAnthropic should not modify model IDs without @', async () => {+ let capturedBody: any = null;++ globalThis.fetch = async (_url: any, init: any) => {+ capturedBody = JSON.parse(init.body);+ return new Response(JSON.stringify({ type: 'message', content: [] }), { status: 200 });+ };++ const request = new Request('http://localhost/v1/messages', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({+ model: 'claude-opus-4-6',+ max_tokens: 100,+ messages: [{ role: 'user', content: 'test' }],+ }),+ });++ await proxyToAnthropic(request, 'sk-ant-test-key');++ expect(capturedBody.model).toBe('claude-opus-4-6');+ });++ it('proxyToAnthropic should handle opus @YYYYMMDD format', async () => {+ let capturedBody: any = null;++ globalThis.fetch = async (_url: any, init: any) => {+ capturedBody = JSON.parse(init.body);+ return new Response(JSON.stringify({ type: 'message', content: [] }), { status: 200 });+ };++ const request = new Request('http://localhost/v1/messages', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({+ model: 'claude-opus-4-5@20251101',+ max_tokens: 100,+ messages: [{ role: 'user', content: 'test' }],+ }),+ });++ await proxyToAnthropic(request, 'sk-ant-test-key');++ expect(capturedBody.model).toBe('claude-opus-4-5-20251101');+ });+});+// ============================================================================// Regression: sanitizeMessages still works (from vertex.ts, shared)// ============================================================================