From d4079825ee38812f2d59485c063efc07a087db03 Mon Sep 17 00:00:00 2001 From: Tom Aylott Date: Tue, 11 Nov 2025 16:59:18 -0500 Subject: [PATCH 1/2] Add prompt-caching placeholder for OpenRouter SDK - Add typescript/openrouter-sdk/src/prompt-caching/README.md - Placeholder for future @openrouter/sdk examples - Will follow same pattern as other SDKs (separate files per scenario) --- docs/prompt-caching.md | 1 + typescript/openrouter-sdk/README.md | 16 +++++++++++ typescript/openrouter-sdk/package.json | 15 +++++++++++ .../src/prompt-caching/README.md | 27 +++++++++++++++++++ typescript/package.json | 3 ++- 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 typescript/openrouter-sdk/README.md create mode 100644 typescript/openrouter-sdk/package.json create mode 100644 typescript/openrouter-sdk/src/prompt-caching/README.md diff --git a/docs/prompt-caching.md b/docs/prompt-caching.md index 9973b95..0fc23ab 100644 --- a/docs/prompt-caching.md +++ b/docs/prompt-caching.md @@ -190,3 +190,4 @@ See ecosystem-specific examples: - **TypeScript + fetch**: [typescript/fetch/src/prompt-caching/](../typescript/fetch/src/prompt-caching/) - **AI SDK v5** (Vercel): [typescript/ai-sdk-v5/src/prompt-caching/](../typescript/ai-sdk-v5/src/prompt-caching/) - **Effect AI** (@effect/ai): [typescript/effect-ai/src/prompt-caching/](../typescript/effect-ai/src/prompt-caching/) +- **OpenRouter SDK** (@openrouter/sdk): [typescript/openrouter-sdk/src/prompt-caching/](../typescript/openrouter-sdk/src/prompt-caching/) diff --git a/typescript/openrouter-sdk/README.md b/typescript/openrouter-sdk/README.md new file mode 100644 index 0000000..c26d9c6 --- /dev/null +++ b/typescript/openrouter-sdk/README.md @@ -0,0 +1,16 @@ +# OpenRouter TypeScript SDK Examples + +Examples using the official @openrouter/sdk package. + +## Status + +**TODO**: Examples not yet implemented + +## Prerequisites + +- Bun runtime: `curl -fsSL https://bun.sh/install | bash` +- `OPENROUTER_API_KEY` environment variable + +## Planned Features + +- [ ] prompt-caching.ts - Anthropic caching with OpenRouter SDK diff --git a/typescript/openrouter-sdk/package.json b/typescript/openrouter-sdk/package.json new file mode 100644 index 0000000..6cf8810 --- /dev/null +++ b/typescript/openrouter-sdk/package.json @@ -0,0 +1,15 @@ +{ + "name": "@openrouter-examples/openrouter-sdk", + "version": "1.0.0", + "private": true, + "type": "module", + "scripts": { + "examples": "echo 'TODO: OpenRouter SDK examples not yet implemented'" + }, + "dependencies": { + "@openrouter-examples/shared": "workspace:*" + }, + "devDependencies": { + "@types/bun": "latest" + } +} diff --git a/typescript/openrouter-sdk/src/prompt-caching/README.md b/typescript/openrouter-sdk/src/prompt-caching/README.md new file mode 100644 index 0000000..18618b9 --- /dev/null +++ b/typescript/openrouter-sdk/src/prompt-caching/README.md @@ -0,0 +1,27 @@ +# Anthropic Prompt Caching Examples (OpenRouter SDK) + +**TODO**: Add prompt caching examples using the @openrouter/sdk package. + +This directory will contain examples demonstrating Anthropic's prompt caching feature via the OpenRouter TypeScript SDK. + +## Placeholder + +Examples will be added in a future commit. + +## Expected Structure + +``` +prompt-caching/ +├── README.md # This file +├── system-message-cache.ts # TODO: Cache on system message +├── user-message-cache.ts # TODO: Cache on user message +├── multi-message-cache.ts # TODO: Cache in conversation +└── no-cache-control.ts # TODO: Control scenario +``` + +## Pattern (To Be Implemented) + +The examples will use the official @openrouter/sdk package to demonstrate: +- How to configure cache_control with the SDK +- Where cache metrics appear in responses +- Evidence-based verification of cache behavior diff --git a/typescript/package.json b/typescript/package.json index 2e0ec08..305eea9 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -13,7 +13,8 @@ "shared", "fetch", "ai-sdk-v5", - "effect-ai" + "effect-ai", + "openrouter-sdk" ], "devDependencies": { "@types/bun": "latest", From 13a711de976b0758c3fe3c43b5d805c2d12a0262 Mon Sep 17 00:00:00 2001 From: Tom Aylott Date: Tue, 11 Nov 2025 18:41:34 -0500 Subject: [PATCH 2/2] Simplify OpenRouter SDK prompt-caching README to link to main docs --- .../src/prompt-caching/README.md | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/typescript/openrouter-sdk/src/prompt-caching/README.md b/typescript/openrouter-sdk/src/prompt-caching/README.md index 18618b9..b0888af 100644 --- a/typescript/openrouter-sdk/src/prompt-caching/README.md +++ b/typescript/openrouter-sdk/src/prompt-caching/README.md @@ -1,27 +1,28 @@ -# Anthropic Prompt Caching Examples (OpenRouter SDK) +# Prompt Caching Examples (OpenRouter SDK) -**TODO**: Add prompt caching examples using the @openrouter/sdk package. +Examples demonstrating prompt caching with @openrouter/sdk. -This directory will contain examples demonstrating Anthropic's prompt caching feature via the OpenRouter TypeScript SDK. +## Documentation -## Placeholder +For full prompt caching documentation including all providers, pricing, and configuration details, see: +- **[Prompt Caching Guide](../../../../docs/prompt-caching.md)** -Examples will be added in a future commit. +## Status -## Expected Structure +**TODO**: Examples coming soon. This directory will contain: +- `user-message-cache.ts` - Cache large context in user messages +- `multi-message-cache.ts` - Cache system prompt across multi-turn conversations +- `no-cache-control.ts` - Control scenario (validates methodology) -``` -prompt-caching/ -├── README.md # This file -├── system-message-cache.ts # TODO: Cache on system message -├── user-message-cache.ts # TODO: Cache on user message -├── multi-message-cache.ts # TODO: Cache in conversation -└── no-cache-control.ts # TODO: Control scenario -``` +## Expected Usage -## Pattern (To Be Implemented) +```typescript +import OpenRouter from '@openrouter/sdk'; -The examples will use the official @openrouter/sdk package to demonstrate: -- How to configure cache_control with the SDK -- Where cache metrics appear in responses -- Evidence-based verification of cache behavior +const openrouter = new OpenRouter({ + apiKey: process.env.OPENROUTER_API_KEY, +}); + +// Configuration and cache_control usage pattern will be documented +// when examples are implemented +```