Skip to content

fix(llm): pin LLM edge functions to US/EU regions to fix geo-block 403s#2541

Merged
koala73 merged 1 commit intomainfrom
worktree-virtual-gliding-spindle
Mar 30, 2026
Merged

fix(llm): pin LLM edge functions to US/EU regions to fix geo-block 403s#2541
koala73 merged 1 commit intomainfrom
worktree-virtual-gliding-spindle

Conversation

@koala73
Copy link
Copy Markdown
Owner

@koala73 koala73 commented Mar 30, 2026

Summary

  • Root cause: OpenRouter returns 403 "This model is not available in your region" when Vercel routes LLM-calling edge functions through nodes in regions where Google Gemini is geo-blocked (Middle East, East Asia, etc.)
  • Affected endpoints: /api/chat-analyst, /api/news/v1/* (article summarization), /api/intelligence/v1/*
  • Fix: Pin the three edge functions to ['iad1', 'lhr1', 'fra1', 'sfo1'] (Virginia, London, Frankfurt, San Francisco) where all OpenRouter-routed LLM providers have full availability
  • Also: Improves callLlmReasoningStream error logging to include model name + full response body on non-2xx for easier future diagnosis

Diagnosed by pulling Vercel production logs which revealed:

[SummarizeArticle:openrouter] API error: 403 {"error":{"message":"This model is not available in your region.","code":403}}

Test plan

  • Deploy and trigger /api/chat-analyst from a VPN endpoint in a geo-blocked region (e.g. UAE, Turkey)
  • Confirm no llm_unavailable errors in Vercel function logs
  • Confirm article summarization still works globally
  • Verify latency impact is minimal (LLM inference dominates, not routing hop)

…k 403s

OpenRouter returns 403 'This model is not available in your region' when
Vercel routes through edge nodes in regions where Google Gemini is blocked.
Pin chat-analyst, news, and intelligence edge functions to iad1/lhr1/fra1/sfo1.

Also improves error logging in callLlmReasoningStream to include model name
and full response body on non-2xx for easier future diagnosis.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
worldmonitor Ignored Ignored Mar 30, 2026 6:52am

Request Review

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 30, 2026

Greptile Summary

This PR pins three LLM-calling Vercel edge functions (/api/chat-analyst, /api/news/v1/*, /api/intelligence/v1/*) to US and EU regions (iad1, lhr1, fra1, sfo1) to prevent 403 geo-block errors from OpenRouter when Vercel routes requests through nodes in restricted regions (Middle East, East Asia, etc.). It also improves error logging in callLlmReasoningStream to capture the model name and first 300 characters of the response body on non-2xx responses, making future diagnosis faster.

  • Region pinning is applied consistently to all three affected edge functions with the same four-region list.
  • Error logging improvement reads the response body via resp.text() only when resp.body is non-null, guarded with .catch(() => '') so any abort or read failure degrades gracefully to an empty string.
  • The clearTimeout is called before the new await resp.text() read; the client AbortController signal remains active and can still interrupt a hanging body read if the client disconnects — acceptable for a typically-small error payload.
  • No changes to request handling logic or auth; the fix is purely infrastructural.

Confidence Score: 5/5

Safe to merge — targeted infrastructure fix with no logic changes and proper error handling guards.

All four files contain only mechanical, low-risk changes: three one-line config additions and one tightly-scoped logging improvement. No auth, caching, or data-path logic is touched. The .catch(() => '') guard in the logging path prevents any new failure mode. No P0 or P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
api/chat-analyst.ts Adds regions: ['iad1', 'lhr1', 'fra1', 'sfo1'] to the Vercel edge config to pin this LLM-calling endpoint away from geo-blocked regions.
api/intelligence/v1/[rpc].ts Identical region-pinning fix applied to the intelligence RPC gateway edge function.
api/news/v1/[rpc].ts Identical region-pinning fix applied to the news RPC gateway edge function (article summarization).
server/_shared/llm.ts Improves non-2xx error logging in callLlmReasoningStream to include the model name and first 300 chars of the response body, aiding future geo-block diagnosis.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Vercel_Edge as Vercel Edge<br/>(iad1/lhr1/fra1/sfo1)
    participant OpenRouter
    participant LLM as LLM Provider<br/>(e.g. Gemini)

    Client->>Vercel_Edge: POST /api/chat-analyst<br/>or /api/news/v1/* or /api/intelligence/v1/*
    Note over Vercel_Edge: regions config pins routing<br/>to US/EU nodes only

    Vercel_Edge->>OpenRouter: POST streaming request<br/>(model, messages, stream:true)
    OpenRouter->>LLM: Forward to LLM provider

    alt Success (2xx + body)
        LLM-->>OpenRouter: SSE stream
        OpenRouter-->>Vercel_Edge: SSE chunks
        Vercel_Edge-->>Client: data: {"delta":"..."}
        Vercel_Edge-->>Client: data: {"done":true}
    else Non-2xx or no body (e.g. 403 geo-block)
        OpenRouter-->>Vercel_Edge: HTTP 4xx/5xx
        Note over Vercel_Edge: clearTimeout, read errBody<br/>log: HTTP 403 model=X body={"error":...}
        Vercel_Edge->>OpenRouter: Retry next provider
    end
Loading

Reviews (1): Last reviewed commit: "fix(llm): pin LLM edge functions to US/E..." | Re-trigger Greptile

@koala73 koala73 merged commit cf5328f into main Mar 30, 2026
8 checks passed
@koala73 koala73 deleted the worktree-virtual-gliding-spindle branch March 30, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant