Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ id: 8b6cd71c-ea04-44da-af45-e43968b5928d
management:
docChecksum: 91fac1777f65751c0821fcc871339214
docVersion: 1.0.0
speakeasyVersion: 1.638.2
generationVersion: 2.729.3
speakeasyVersion: 1.639.0
generationVersion: 2.730.0
releaseVersion: 0.0.1-beta.6
configChecksum: 550c3a591fe28e4437bad9246d74cc8b
configChecksum: 2991fa5c177f7315bcfe0a736b115aa0
repoURL: https://github.com/OpenRouterTeam/typescript-sdk.git
installationURL: https://github.com/OpenRouterTeam/typescript-sdk
published: true
Expand All @@ -15,7 +15,7 @@ features:
acceptHeaders: 2.81.2
additionalDependencies: 0.1.0
constsAndDefaults: 0.1.12
core: 3.23.0
core: 3.24.0
customCodeRegions: 0.1.0
defaultEnabledRetries: 0.1.0
deprecations: 2.81.1
Expand Down Expand Up @@ -1370,6 +1370,3 @@ examples:
5XX:
application/json: {"error": {"code": 400, "message": "Invalid request parameters", "metadata": {"field": "temperature", "reason": "Must be between 0 and 2"}}, "user_id": "user-abc123"}
examplesVersion: 1.0.2
releaseNotes: |
## Typescript SDK Changes Detected:
* `openrouter.beta.responses.send()`: `response` **Changed**
7 changes: 6 additions & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ typescript:
dependencies: {}
devDependencies:
vitest: ^3.2.4
peerDependencies: {}
peerDependencies:
'@modelcontextprotocol/sdk': ^1.20.1
mcp-client: ^1.13.1
zod: ^3.25.0 || ^4.0.0
zod-to-json-schema: ^3.24.6
additionalPackageJSON: {}
author: OpenRouter
baseErrorName: OpenRouterError
Expand Down Expand Up @@ -72,3 +76,4 @@ typescript:
templateVersion: v2
usageSDKInitImports: []
useIndexModules: true
zodVersion: v3
5 changes: 2 additions & 3 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
speakeasyVersion: 1.638.2
speakeasyVersion: 1.639.0
sources:
OpenRouter API:
sourceNamespace: open-router-chat-completions-api
sourceRevisionDigest: sha256:e02ee82928a7d3f9c1d3efa2cb5015a9a8be0ee1bd83aff728f59d4cf898c842
sourceBlobDigest: sha256:87a961c88ed7c186853a3d8221bbf4bcd35108f263bb8e03ab2fd5ab31b81b29
tags:
- latest
- speakeasy-sdk-regen-1761240253
- 1.0.0
targets:
openrouter:
Expand All @@ -15,7 +14,7 @@ targets:
sourceRevisionDigest: sha256:e02ee82928a7d3f9c1d3efa2cb5015a9a8be0ee1bd83aff728f59d4cf898c842
sourceBlobDigest: sha256:87a961c88ed7c186853a3d8221bbf4bcd35108f263bb8e03ab2fd5ab31b81b29
codeSamplesNamespace: open-router-chat-completions-api-typescript-code-samples
codeSamplesRevisionDigest: sha256:345e2d0a457fd984dc7ead6ad419a1a7f8245b9441a431f36978d8b22b7ea6c5
codeSamplesRevisionDigest: sha256:f1b9f44c9a7f4d793b94e31dd8b96c82896cb307be663cca03339b1b4d387f84
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand Down
114 changes: 114 additions & 0 deletions examples/nextjs-example/src/app/(app)/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { OpenRouter } from '@openrouter/sdk'
import z from 'zod'

const openRouter = new OpenRouter()



const chatResponse = await openRouter.chat.experimental_send({
model: "openai/gpt-4o",
messages: [
{
role: "user",
content: "What is the weather in Bogotá, Colombia?",
},
],
stream: false,
tools: [
{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/sse",
"require_approval": "never"
},
{
type: 'function',
function: {
name: "get_weather",
description: "Get current temperature for a given location.",
parameters: z.object({
location: z.string().describe("City and country e.g. Bogotá, Colombia"),
}).strict(),
// Required
returns: z.object({
temperature: z.number(),
description: z.string(),
}).describe("Temperature and description of the weather"),

// if a function is provided, it will be called with the parameters and the result will be returned, re-calling the model again
// rather then simply having the tool call be the final response
run: async (parameters) => {
// type checking will enfoce that the return value matches the schema defined in returns
return {
temperature: 20,
description: "Clear skies",
}
}
}
}
],
outputSchema: z.object({
temperature: z.number(),
description: z.string(),
}),
})

if ('choices' in chatResponse) {
// chatResponse
// the raw response from the API in openai chat format
chatResponse.choices[0].message
// Will contain all the new turns of the conversation. all tool calls and responses are fully typed
// and cleaned up to not have choices etc. a more user friendly version of the raw response
chatResponse.allNewMessages
// Will contain the final message of the conversation. content is always an array. all tool calls and responses are fully typed
chatResponse.responseMessage
// The text only response of the conversation or null if the final response was a tool call
chatResponse.responseText
// The final message of the conversation as a fully typed function call
chatResponse.responseFunctionCall
// the output that is fully validated and typed in json/object/array format
chatResponse.output

} else {
// chatResponse is a stream
for await (const chunk of chatResponse.fullStream) {
// the raw response from the API in openai chat streaming format
chunk.raw.data.choices[0].delta
// the chunked version of allNewMessages
chunk.message
}

for await (const chunk of chatResponse.response) {

// the chunked version of the final response message only with all content chunks and fully typed
chunk.message
// Just the text content of the final response message or null
chunk.text
// The final message of the conversation as a fully typed function call
chunk.functionCall
// the output that is fully validated and typed in json/object/array format
chunk.output
}
}

// openRouter.beta.responses.send({
// tools: [
// {
// "type": "mcp",
// "server_label": "dmcp",
// "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
// "server_url": "https://dmcp-server.deno.dev/sse",
// "require_approval": "never"
// },
// {
// type: 'function',
// name: "get_weather",
// description: "Get current temperature for a given location.",
// parameters: z.object({
// location: z.string().describe("City and country e.g. Bogotá, Colombia"),
// }).strict(),
// }
// ]
// })

Loading