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
2 changes: 1 addition & 1 deletion apps/web/src/app/api/gateway/[...path]/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { POST } from '@/app/api/openrouter/[...path]/route';

export const maxDuration = 1800;
export const maxDuration = 800;
2 changes: 1 addition & 1 deletion apps/web/src/app/api/gateway/audio/transcriptions/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { POST } from '@/app/api/openrouter/audio/transcriptions/route';

export const maxDuration = 1800;
export const maxDuration = 800;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { POST } from '@/app/api/openrouter/audio/transcriptions/route';

export const maxDuration = 1800;
export const maxDuration = 800;
4 changes: 2 additions & 2 deletions apps/web/src/app/api/openrouter/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import {
import { redactProviderHints } from '@kilocode/auto-routing-contracts';
import { logExceptInTest } from '@/lib/utils.server';

export const maxDuration = 1800;
export const maxDuration = 800;

const MAX_TOKENS_LIMIT = 99999999999; // GPT4.1 default is ~32k

Expand Down Expand Up @@ -621,7 +621,7 @@ export async function POST(request: NextRequest): Promise<NextResponseType<unkno
// previously blocking/quarantine decision wait for a fresh abuse-service result.
const shouldBlockOnClassify = isRulesEngineBlockingAction(cachedRulesEngineAction);

// Large responses may run longer than the 1800s serverless function timeout.
// Large responses may run longer than the 800s serverless function timeout.
const requestMaxTokens = getMaxTokens(requestBodyParsed);
if (requestMaxTokens && requestMaxTokens > MAX_TOKENS_LIMIT) {
console.warn(`SECURITY: Max tokens limit exceeded: ${user.id}`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('POST /api/gateway/v1/audio/transcriptions', () => {
import('@/app/api/gateway/v1/audio/transcriptions/route'),
]);

expect(routes.map(route => route.maxDuration)).toEqual([1800, 1800, 1800, 1800]);
expect(routes.map(route => route.maxDuration)).toEqual([800, 800, 800, 800]);
});

it('proxies transcription requests to OpenRouter', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from '@/lib/ai-gateway/transcriptions/transcription-request';
import type { Provider } from '@/lib/ai-gateway/providers/types';

export const maxDuration = 1800;
export const maxDuration = 800;

const PAID_MODEL_AUTH_REQUIRED = 'PAID_MODEL_AUTH_REQUIRED';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { POST } from '@/app/api/openrouter/audio/transcriptions/route';

export const maxDuration = 1800;
export const maxDuration = 800;
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('fetchGeneration', () => {
jest.useRealTimers();
});

it('uses a longer, slower retry window', async () => {
it('limits generation polling to about one minute', async () => {
mockFetchWithBackoff.mockResolvedValue(
new Response(JSON.stringify({ id: 'generation-id' }), {
status: 200,
Expand All @@ -56,7 +56,7 @@ describe('fetchGeneration', () => {
},
expect.objectContaining({
baseDelayMs: 5_000,
maxDelayMs: 5 * 60 * 1_000,
maxDelayMs: 75 * 1_000,
})
);

Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/lib/ai-gateway/providers/upstream-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type UpstreamFetchFailureFamily =
| 'abort'
| 'unknown';

// Longer than Vercel AI Gateway's 13min timeout, shorter than Vercel Function's 30min timeout.
const TIMEOUT_MS = 15 * 60 * 1000;
const GENERATION_FETCH_MAX_DELAY_MS = 5 * 60 * 1000;
// Leave 200s of the Vercel function budget for post-stream work.
const TIMEOUT_MS = 10 * 60 * 1000;
// fetchWithBackoff reserves the next delay before retrying, so 75s yields about one minute.
const GENERATION_FETCH_MAX_DELAY_MS = 75 * 1000;
Comment thread
chrarnoldus marked this conversation as resolved.

function getProviderTargetHost(apiUrl: string): string {
try {
Expand Down