Skip to content

Bug: SDK and Direct API Calls Suddenly Failing — "Unexpected end of JSON input" / Invalid JWT Format #27

@RichmondRamil

Description

@RichmondRamil

Environment

  • SDK: [openrouter SDK using openai.chat.completions.create()]
  • API: https://openrouter.ai/api/v1/chat/completions
  • Server: Node.js (backend)
  • Auth: Bearer token via process.env.VALIDATE_OPEN_ROUTER_KEY
  • Model: google/gemini-2.5-flash-lite-preview-06-17
  • Status: Worked fine yesterday, broken today

Problem Summary
Both the SDK call and a manual fetch call to the OpenRouter endpoint are failing today, even though they were working perfectly yesterday.

Expected Behavior
Should return a valid JSON response from the model completion endpoint for a simple user prompt.

Steps to Reproduce

  1. SDK usage:
    `const openai = new OpenAI({
    baseURL: 'https://openrouter.ai/api/v1',
    apiKey: process.env.VALIDATE_OPEN_ROUTER_KEY,
    });

const messages = [{ role: 'user', content: 'Hello' }];
const model = 'google/gemini-2.5-flash-lite-preview-06-17';

const completion = await openai.chat.completions.create({ model, messages });`

Error Output:
❌ Chat failed: SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at parseJSONFromBytes ...

  1. Direct fetch call:
    const response = await fetch('https://openrouter.ai/api/v1/chat/completions', { method: 'POST', headers: { Authorization: Bearer ${process.env.VALIDATE_OPEN_ROUTER_KEY}, 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'google/gemini-2.5-flash-lite-preview-06-17', messages: [{ role: 'user', content: 'Hello' }], }), });

Response status: 200 OK
But headers include:
{ "x-clerk-auth-message": "Invalid JWT form. A JWT consists of three parts separated by dots. (reason=token-invalid, token-carrier=header)" }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions