File tree Expand file tree Collapse file tree 1 file changed +1
-23
lines changed
typescript/fetch/src/basic Expand file tree Collapse file tree 1 file changed +1
-23
lines changed Original file line number Diff line number Diff line change 33 *
44 * This example demonstrates how to make direct HTTP requests to OpenRouter's API
55 * using the native fetch API without any additional libraries.
6- *
7- * To run: bun examples/basic/example-basic-fetch.ts
86 */
97
10- // Make this a module
11- export { } ;
8+ import type { ChatCompletionResponse } from '@openrouter-examples/shared/types' ;
129
1310// OpenRouter API endpoint
1411const OPENROUTER_API_URL = 'https://openrouter.ai/api/v1/chat/completions' ;
1512
16- // Type definitions for the API response
17- interface ChatCompletionResponse {
18- id : string ;
19- model : string ;
20- choices : Array < {
21- index : number ;
22- message : {
23- role : string ;
24- content : string ;
25- } ;
26- finish_reason : string ;
27- } > ;
28- usage : {
29- prompt_tokens : number ;
30- completion_tokens : number ;
31- total_tokens : number ;
32- } ;
33- }
34-
3513// Request payload following OpenAI-compatible chat completions format
3614const requestBody = {
3715 model : 'openai/gpt-4o-mini' ,
You can’t perform that action at this time.
0 commit comments