typescript-sdk_skill

This skill helps AI agents integrate with OpenRouter TypeScript SDK to callModel with type safety and multi-turn support.

13

GitHub Stars

2

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill openrouterteam/agent-skills --skill typescript-sdk

  • metadata.json1007 B
  • SKILL.md29.6 KB

Overview

This skill provides a complete reference for integrating with 300+ AI models using the OpenRouter TypeScript SDK and the callModel pattern. It documents authentication (API key and OAuth PKCE), input formats, streaming and synchronous response methods, tool creation, multi-turn flows, and security suggestions. The content is focused on practical code examples and patterns for production usage.

How this skill works

The SDK exposes a single, type-safe callModel function that accepts flexible inputs (strings, message arrays, multimodal content) and returns a result object with multiple consumption methods (getText, getResponse, getTextStream, etc.). It handles API key and OAuth PKCE authentication, automatic tool execution, streaming, and multi-turn conversations, while allowing dynamic parameters and stop conditions. Tools are defined with strong typing (Zod) and can be regular, generator, or manual, including hooks to modify next-turn parameters.

When to use it

  • Implement text generation, summarization, or chat features across many model providers through a unified API.
  • Build user-facing apps where users manage their own keys via OAuth PKCE.
  • Execute external logic automatically during generation using typed tools (APIs, databases, web search).
  • Stream responses to clients or consume full responses server-side with usage metadata.
  • Run multi-turn workflows with stop conditions, cost limits, or tool-driven control flows.

Best practices

  • Store API keys in environment variables and rotate keys regularly using the key management API.
  • Use OAuth PKCE for user-owned keys so the app never handles user credentials directly.
  • Define tools with Zod schemas for automatic input/output validation and safer execution.
  • Prefer streaming (getTextStream) for low-latency UX and getResponse for auditing token usage and costs.
  • Use stopWhen conditions and minimal-scoped keys to limit unexpected costs or runaway loops.

Example use cases

  • Chatbot backed by multiple model providers selectable at runtime via callModel dynamic parameters.
  • Search + analyze pipeline where a web_search generator tool streams progress events while the model composes results.
  • User-authenticated apps: start OAuth flow, exchange code for a user API key, then callModel with the user's key.
  • Background agents that call tools (calculators, databases) automatically and continue the conversation using nextTurnParams.
  • Live streaming editor that displays tokens as they arrive using getTextStream for collaborative writing.

FAQ

Use API keys stored in environment variables. They are simpler for server-to-server integration and can be managed programmatically via the key management API.

How do I stream partial output to clients?

Call result.getTextStream() and iterate async for deltas to forward to your client (WebSocket, SSE, or HTTP chunking).

Can tools change the model or temperature for the next turn?

Yes. Tools can provide nextTurnParams that compute instructions, model selection, or temperature based on tool output and the current context.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational