-
Notifications
You must be signed in to change notification settings - Fork 43
Add basic OpenRouter SDK example extracted from wrapper repo #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 05-prompt-caching-orsdk
Are you sure you want to change the base?
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this 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.
88d58da to
909ba4d
Compare
f4c8858 to
2701c37
Compare
909ba4d to
7225576
Compare
2701c37 to
1e838d6
Compare
1e838d6 to
f5b54a8
Compare
| 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(); |
There was a problem hiding this comment.
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
| 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; | ||
| } |
There was a problem hiding this comment.
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

Add basic OpenRouter SDK example extracted from wrapper repo
Run biome format