Skip to content
Open
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
typescript/node_modules/
typescript/*/node_modules/
typescript/bun.lock
*.log
.DS_Store
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Makefile - Root orchestration for openrouter-examples

.PHONY: help examples typescript install clean

help:
@echo "OpenRouter Examples - Available commands:"
@echo ""
@echo " make examples - Run all examples"
@echo " make typescript - Run TypeScript monorepo examples"
@echo " make install - Install TypeScript dependencies"
@echo " make clean - Clean node_modules and lockfiles"
@echo ""

# Run all examples
examples: typescript

# Run TypeScript monorepo examples
typescript:
@echo "=== Running TypeScript examples ==="
@cd typescript && bun examples

# Install TypeScript dependencies
install:
@echo "=== Installing TypeScript dependencies ==="
@cd typescript && bun install

# Clean build artifacts
clean:
@echo "=== Cleaning TypeScript artifacts ==="
@rm -rf typescript/node_modules
@rm -rf typescript/*/node_modules
@rm -rf typescript/bun.lock
@echo "Clean complete"
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# OpenRouter Examples

Comprehensive, tested, executable examples demonstrating OpenRouter features across multiple ecosystems.

## Quick Start

```bash
# Set your API key
export OPENROUTER_API_KEY="your-key-here"

# Run all examples
make examples

# Or run specific ecosystems
make curl # Run curl examples
make typescript # Run TypeScript monorepo examples
```

## Repository Structure

```
.
├── curl/ - Shell script examples
├── typescript/ - TypeScript monorepo (Bun workspaces)
│ ├── shared/ - Shared constants and types
│ ├── fetch/ - Raw fetch API examples
│ ├── ai-sdk-v5/ - Vercel AI SDK v5 examples
│ ├── effect-ai/ - Effect-TS examples
│ └── openrouter-sdk/ - OpenRouter SDK examples (TODO)
├── docs/ - Feature documentation
└── Makefile - Unified command interface
```

## Features

### Prompt Caching
- **Documentation**: [docs/prompt-caching.md](docs/prompt-caching.md)
- **Examples**:
- [curl/prompt-caching.sh](curl/prompt-caching.sh)
- [typescript/fetch/src/prompt-caching/](typescript/fetch/src/prompt-caching/)
- [typescript/ai-sdk-v5/src/prompt-caching/](typescript/ai-sdk-v5/src/prompt-caching/)
- [typescript/effect-ai/src/prompt-caching/](typescript/effect-ai/src/prompt-caching/)

## Prerequisites

- Bun runtime: `curl -fsSL https://bun.sh/install | bash`
- OpenRouter API key: [https://openrouter.ai/keys](https://openrouter.ai/keys)
- For curl examples: `jq` (JSON processor)

## Installation

```bash
# Install TypeScript dependencies
make install

# Or manually
cd typescript && bun install
```

## Running Examples

### All Examples
```bash
make examples
```

### By Ecosystem
```bash
make curl # Shell scripts with curl + jq
make typescript # All TypeScript examples (fetch, AI SDK, Effect)
```

### Individual Examples
```bash
# curl
bash curl/prompt-caching.sh

# TypeScript
cd typescript/fetch && bun examples
cd typescript/ai-sdk-v5 && bun examples
cd typescript/effect-ai && bun examples
```

## Benefits

### For Users
1. **Copy-paste ready** - All examples are runnable as-is
2. **Tested and proven** - Every example has been verified to work
3. **Evidence-based** - Examples show expected outputs and verification
4. **Multiple ecosystems** - Choose the one that matches your stack

### For Developers
1. **Single source of truth** - Constants defined once in `typescript/shared/`
2. **Type safety** - Shared types across all TypeScript examples
3. **Consistent patterns** - Each ecosystem follows its own idioms
4. **Easy maintenance** - Bun monorepo for TypeScript workspaces

## Contributing

See individual ecosystem READMEs:
- [curl/README.md](curl/README.md)
- [typescript/README.md](typescript/README.md)

## License

See [LICENSE.md](LICENSE.md)
99 changes: 99 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"$schema": "https://biomejs.dev/schemas/2.3.3/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false,
"ignore": [
"**/*.json",
"!biome.json"
]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 100,
"attributePosition": "multiline"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"useLiteralKeys": "off",
"noExtraBooleanCast": "off",
"noForEach": "off",
"noBannedTypes": "error",
"noUselessSwitchCase": "off"
},
"style": {
"noNonNullAssertion": "off",
"useNodejsImportProtocol": "off",
"useTemplate": "off",
"useBlockStatements": "error",
"noParameterAssign": "error",
"useConst": "error",
"useAsConstAssertion": "error",
"useDefaultParameterLast": "error",
"useEnumInitializers": "error",
"useSelfClosingElements": "error",
"useSingleVarDeclarator": "error",
"noUnusedTemplateLiteral": "error",
"useNumberNamespace": "error",
"noInferrableTypes": "error",
"noUselessElse": "error",
"useImportType": "error"
},
"correctness": {
"noUnusedImports": "error",
"useExhaustiveDependencies": "off",
"noUnknownFunction": "off",
"noChildrenProp": "off",
"noInnerDeclarations": "error"
},
"suspicious": {
"noExplicitAny": "error",
"noArrayIndexKey": "off",
"noAssignInExpressions": "error",
"noAsyncPromiseExecutor": "off",
"noFallthroughSwitchClause": "error",
"noConsole": "off",
"noDoubleEquals": {
"level": "error",
"options": {
"ignoreNull": false
}
},
"noExtraNonNullAssertion": "error"
},
"performance": {
"recommended": true,
"noAccumulatingSpread": "error"
},
"security": {
"recommended": true
}
}
},
"javascript": {
"formatter": {
"lineWidth": 100,
"arrowParentheses": "always",
"jsxQuoteStyle": "single",
"attributePosition": "multiline",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single"
}
}
}
Loading