Skip to content

chat.send() overloads do not narrow the response type #796

Description

@kritikmodi

Environment

  • openrouter/sdk@1.2.27
  • TypeScript 5.9.3
  • NodeNext module resolution

Problem

chat.send() has separate overloads for stream?: false and stream: true, but both return:

ChatResult | EventStream<ChatStreamChunk>

This makes both documented usage patterns fail TypeScript.

Non-streaming

const completion = await client.chat.send({
  chatRequest: {
    model: "openai/gpt-5-mini",
    messages: [{ role: "user", content: "Hello" }],
    stream: false,
  },
});

console.log(completion.choices[0]);
TS2339: Property 'choices' does not exist on type
'SendChatCompletionRequestResponse'.

Streaming

const stream = await client.chat.send({
  chatRequest: {
    model: "openai/gpt-5-mini",
    messages: [{ role: "user", content: "Hello" }],
    stream: true,
  },
});

for await (const chunk of stream) {
  console.log(chunk);
}
TS2504: SendChatCompletionRequestResponse must have a
[Symbol.asyncIterator]() method.

Expected

The overloads should return:

stream?: false  Promise<ChatResult>
stream: true    Promise<EventStream<ChatStreamChunk>>

The union is only necessary when the streaming mode is not statically known.

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