Add basic OpenRouter SDK example extracted from wrapper repo#46
Add basic OpenRouter SDK example extracted from wrapper repo#46subtleGradient wants to merge 3 commits into05-prompt-caching-orsdkfrom
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.
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.
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.
would love to pull this out into a function
13a711d to
c136b23
Compare
f5b54a8 to
5e8035e
Compare
2be23db to
94c6b34
Compare
5e8035e to
635c0fa
Compare

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