skalpel 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -0
- package/dist/cli/index.js +1660 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/proxy-runner.js +291 -0
- package/dist/cli/proxy-runner.js.map +1 -0
- package/dist/index.cjs +852 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +135 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +799 -0
- package/dist/index.js.map +1 -0
- package/dist/proxy/index.cjs +376 -0
- package/dist/proxy/index.cjs.map +1 -0
- package/dist/proxy/index.d.cts +31 -0
- package/dist/proxy/index.d.ts +31 -0
- package/dist/proxy/index.js +335 -0
- package/dist/proxy/index.js.map +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Skalpel SDK
|
|
2
|
+
|
|
3
|
+
Optimize your OpenAI and Anthropic API calls with Skalpel AI. The SDK transparently reroutes requests through the Skalpel proxy, adding cost optimization, caching, and intelligent model routing — without changing your existing code.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install skalpel
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Wrapper Pattern
|
|
14
|
+
|
|
15
|
+
Wrap your existing client to route all calls through Skalpel with automatic fallback:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import OpenAI from 'openai';
|
|
19
|
+
import { createSkalpelClient } from 'skalpel';
|
|
20
|
+
|
|
21
|
+
const openai = createSkalpelClient(new OpenAI(), {
|
|
22
|
+
apiKey: process.env.SKALPEL_API_KEY!,
|
|
23
|
+
workspace: 'my-workspace',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Use exactly like the OpenAI client
|
|
27
|
+
const response = await openai.chat.completions.create({
|
|
28
|
+
model: 'gpt-4o',
|
|
29
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### URL Swap Pattern
|
|
34
|
+
|
|
35
|
+
The simplest integration — one line change:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { createSkalpelOpenAI } from 'skalpel';
|
|
39
|
+
|
|
40
|
+
const openai = await createSkalpelOpenAI({
|
|
41
|
+
apiKey: process.env.SKALPEL_API_KEY!,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const response = await openai.chat.completions.create({
|
|
45
|
+
model: 'gpt-4o',
|
|
46
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## CLI Setup
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx skalpel init
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Interactive wizard that detects your project type, AI SDKs, and generates the integration code.
|
|
57
|
+
|
|
58
|
+
## API Reference
|
|
59
|
+
|
|
60
|
+
### `createSkalpelClient<T>(client: T, options: SkalpelClientOptions): T`
|
|
61
|
+
|
|
62
|
+
Wraps an existing OpenAI or Anthropic client instance. All API calls are transparently routed through the Skalpel proxy. Supports automatic fallback to the direct provider on errors.
|
|
63
|
+
|
|
64
|
+
### `createSkalpelOpenAI(options): Promise<OpenAI>`
|
|
65
|
+
|
|
66
|
+
Factory function that creates a pre-configured OpenAI client pointing at the Skalpel proxy.
|
|
67
|
+
|
|
68
|
+
### `createSkalpelAnthropic(options): Promise<Anthropic>`
|
|
69
|
+
|
|
70
|
+
Factory function that creates a pre-configured Anthropic client pointing at the Skalpel proxy.
|
|
71
|
+
|
|
72
|
+
### `extractMetadata(headers): SkalpelMetadata | null`
|
|
73
|
+
|
|
74
|
+
Extracts optimization metadata from Skalpel response headers (`x-skalpel-*`).
|
|
75
|
+
|
|
76
|
+
## Error Handling
|
|
77
|
+
|
|
78
|
+
The SDK provides typed error classes:
|
|
79
|
+
|
|
80
|
+
- `SkalpelAuthError` (401) — authentication failed. Never falls back.
|
|
81
|
+
- `SkalpelTimeoutError` — request timed out.
|
|
82
|
+
- `SkalpelRateLimitError` (429) — rate limit exceeded, includes `retryAfter`.
|
|
83
|
+
- `SkalpelUnavailableError` (5xx) — proxy unavailable.
|
|
84
|
+
|
|
85
|
+
When `fallbackOnError: true` (default), the SDK retries with exponential backoff, then falls back to the direct provider. Auth errors always throw immediately.
|
|
86
|
+
|
|
87
|
+
## Configuration
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
interface SkalpelClientOptions {
|
|
91
|
+
apiKey: string; // Skalpel API key (sk-skalpel-*)
|
|
92
|
+
workspace?: string; // Workspace ID
|
|
93
|
+
baseURL?: string; // Proxy URL (default: https://api.skalpel.ai)
|
|
94
|
+
fallbackOnError?: boolean; // Fall back to direct provider (default: true)
|
|
95
|
+
timeout?: number; // Request timeout in ms (default: 30000)
|
|
96
|
+
retries?: number; // Max retries (default: 2)
|
|
97
|
+
headers?: Record<string, string>;// Additional custom headers
|
|
98
|
+
verbose?: boolean; // Log fallback events (default: false)
|
|
99
|
+
onFallback?: (error, provider) => void; // Callback on fallback
|
|
100
|
+
onMetadata?: (metadata) => void; // Callback with optimization info
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## TypeScript
|
|
105
|
+
|
|
106
|
+
The SDK is written in TypeScript and ships with full type declarations. All types are exported:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import type {
|
|
110
|
+
SkalpelClientOptions,
|
|
111
|
+
SkalpelMetadata,
|
|
112
|
+
SkalpelConfig,
|
|
113
|
+
SupportedProvider,
|
|
114
|
+
InitConfig,
|
|
115
|
+
} from 'skalpel';
|
|
116
|
+
```
|