Skip to content

Conversation

@subtleGradient
Copy link
Contributor

Add basic OpenRouter SDK example extracted from wrapper repo

Run biome format

Copy link
Contributor Author

subtleGradient commented Nov 11, 2025

@subtleGradient subtleGradient marked this pull request as ready for review November 11, 2025 23:53
Copilot AI review requested due to automatic review settings November 11, 2025 23:53
Copilot finished reviewing on behalf of subtleGradient November 11, 2025 23:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a basic example demonstrating the OpenRouter TypeScript SDK usage patterns, including both streaming and non-streaming chat completions. This is the first example file for the openrouter-sdk workspace, which previously had a TODO status.

  • Adds a comprehensive example file showing SDK initialization, non-streaming and streaming chat completions
  • Demonstrates async iteration for streaming responses with usage tracking

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +83 to +94
async function main() {
try {
// Demonstrate both streaming and non-streaming modes
await nonStreamingExample();
await streamingExample();
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
}

main();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pick 1 pattern -- either try/catch or main().catch -- generally prefer just naked call or have an utils to wrap the main function

Comment on lines +62 to +71
let fullContent = '';

// The SDK returns an async iterable that you can iterate with for-await-of
for await (const chunk of stream) {
// Each chunk contains partial data
if (chunk.choices?.[0]?.delta?.content) {
const content = chunk.choices[0].delta.content;
process.stdout.write(content); // Write without newline to see real-time streaming
fullContent += content;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would love to pull this out into a function

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.

3 participants