@turnstileai/sdk 0.1.3 → 0.1.5

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 CHANGED
@@ -1,52 +1,70 @@
1
1
  # @turnstileai/sdk
2
2
 
3
- TypeScript SDK for TurnstileAI, a verification-first AI gateway.
3
+ The official TypeScript/JavaScript SDK for TurnstileAI, a verification-first AI gateway for routed completions, run records, and optional ledger-backed checkpoints.
4
4
 
5
- TurnstileAI sits between your application and model providers, then returns
6
- structured run records with routing, latency, usage, cost, digests, signatures,
7
- and optional ledger checkpoints.
8
-
9
- ## Install
5
+ ## Installation
10
6
 
11
7
  ```bash
12
8
  npm install @turnstileai/sdk
13
9
  ```
14
10
 
15
- ## Quick start
11
+ ## Quickstart
12
+
13
+ Initialize the client and send verification-enabled inference completions:
16
14
 
17
15
  ```ts
18
- import OpenAI from "openai";
16
+ import { TurnstileAI } from "@turnstileai/sdk";
19
17
 
20
- const client = new OpenAI({
21
- apiKey: process.env.TURNSTILEAI_API_KEY,
22
- baseURL: "https://api.turnstileai.com/v1"
18
+ const client = new TurnstileAI({
19
+ apiKey: process.env.TURNSTILEAI_API_KEY!
23
20
  });
24
21
 
25
- const response = await client.chat.completions.create({
22
+ const result = await client.chat({
26
23
  model: "openrouter/llama-3.1-70b",
27
24
  messages: [
28
- { role: "user", content: "Explain Solana finality simply." }
25
+ { role: "user", content: "Explain zero-knowledge rollups simply." }
29
26
  ],
30
- extra_body: {
31
- checkpoint: true,
32
- ledger: "solana",
33
- routeMode: "trust-first"
34
- }
27
+ receipt: true,
28
+ anchor: "solana",
29
+ routeMode: "trust-first"
35
30
  });
36
31
 
37
- console.log(response.choices.message.content);
38
- console.log(response.run_record);
32
+ console.log(result.output);
33
+ console.log(JSON.stringify(result.record, null, 2));
34
+ console.log(JSON.stringify(result.verification, null, 2));
39
35
  ```
40
36
 
41
- ## SDK client
37
+ ## Sandboxed Local Testing (No Server Needed)
42
38
 
43
- ```ts
44
- import { TurnstileAI } from "@turnstileai/sdk";
39
+ If the SDK detects an API key starting with `ts_test_` or the environment variable `TURNSTILEAI_MOCK=true` is set, it can fall back to local mock mode for offline development and integration testing.
45
40
 
46
- const client = new TurnstileAI({
47
- apiKey: process.env.TURNSTILEAI_API_KEY!
48
- });
41
+ ## Config Parameters
42
+
43
+ | Parameter | Type | Description |
44
+ | --- | --- | --- |
45
+ | `apiKey` | `string` | Your TurnstileAI API key. |
46
+ | `baseURL` | `string` | The TurnstileAI API base URL, defaults to `https://api.turnstileai.com/v1`. |
47
+ | `timeout` | `number` | Request timeout in milliseconds. |
48
+ | `defaultRouteMode` | `RouteMode` | Optional default routing strategy. |
49
+ | `defaultLedgerMode` | `LedgerMode` | Optional default ledger/checkpoint mode. |
50
+
51
+ ## Chat Options
52
+
53
+ | Option | Type | Default | Description |
54
+ | --- | --- | --- | --- |
55
+ | `model` | `string` | Required | Model routing path such as `openai/gpt-4o-mini` or `openrouter/llama-3.1-70b`. |
56
+ | `messages` | `Array` | Required | Message array with `role` and `content`. |
57
+ | `receipt` | `boolean` | `true` | Include a verification-oriented run record in the response. |
58
+ | `anchor` | `string` | `"off-chain"` | Checkpoint mode: `"solana"`, `"off-chain"`, or `"none"`. |
59
+ | `routeMode` | `string` | `"trust-first"` | Routing strategy for provider selection. |
60
+ | `provider` | `string` | Optional | Pin inference to a provider. |
61
+ | `maxSpendUsd` | `number` | Optional | Set a maximum spend cap for a request. |
62
+ | `temperature` | `number` | Optional | Sampling temperature for completion generation. |
63
+ | `maxTokens` | `number` | Optional | Output token limit. |
49
64
 
65
+ ## Record APIs
66
+
67
+ ```ts
50
68
  const record = await client.records.get("rr_123");
51
69
  const verification = await client.records.verify("rr_123");
52
70
  const providers = await client.providers.list();
@@ -57,22 +75,13 @@ const usage = await client.usage.overview("month");
57
75
 
58
76
  ```bash
59
77
  turnstileai auth check --key=ts_live_xxx
78
+ turnstileai record get rr_123 --key=ts_live_xxx
60
79
  turnstileai record list --key=ts_live_xxx
61
80
  turnstileai record verify rr_123 --key=ts_live_xxx
62
81
  turnstileai providers list --key=ts_live_xxx
63
82
  turnstileai usage overview --key=ts_live_xxx
64
83
  ```
65
84
 
66
- ## Route modes
67
-
68
- - `cost-first`
69
- - `speed-first`
70
- - `trust-first`
71
- - `attested-only`
72
- - `provider-pinned`
73
- - `budget-guarded`
74
-
75
- ## Ledger modes
85
+ ## License
76
86
 
77
- - `none`
78
- - `solana`
87
+ MIT
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_test_1 = __importDefault(require("node:test"));
7
+ const strict_1 = __importDefault(require("node:assert/strict"));
8
+ const client_1 = require("../client");
9
+ (0, node_test_1.default)("TurnstileAI throws when apiKey is missing", () => {
10
+ strict_1.default.throws(() => {
11
+ new client_1.TurnstileAI({ apiKey: "" });
12
+ }, /Missing TurnstileAI API key/);
13
+ });
14
+ (0, node_test_1.default)("TurnstileAI creates a client with valid apiKey", () => {
15
+ const client = new client_1.TurnstileAI({ apiKey: "ts_test_123" });
16
+ strict_1.default.ok(client);
17
+ strict_1.default.ok(client.records);
18
+ strict_1.default.ok(client.providers);
19
+ strict_1.default.ok(client.usage);
20
+ });
package/dist/types.d.ts CHANGED
@@ -73,3 +73,26 @@ export interface TurnstileApiErrorBody {
73
73
  message?: string;
74
74
  details?: unknown;
75
75
  }
76
+ export interface TurnstileChatMessage {
77
+ role: "system" | "user" | "assistant";
78
+ content: string;
79
+ }
80
+ export interface TurnstileChatRequest {
81
+ model: string;
82
+ messages: TurnstileChatMessage[];
83
+ receipt?: boolean;
84
+ anchor?: "solana" | "off-chain" | "none";
85
+ routeMode?: RouteMode;
86
+ provider?: string;
87
+ maxSpendUsd?: number;
88
+ temperature?: number;
89
+ maxTokens?: number;
90
+ }
91
+ export interface TurnstileChatResult {
92
+ id: string;
93
+ model: string;
94
+ provider: string;
95
+ output: string;
96
+ record: RunRecord | null;
97
+ verification: VerificationResult | null;
98
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turnstileai/sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Original TypeScript SDK for TurnstileAI",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,6 +13,7 @@
13
13
  ],
14
14
  "scripts": {
15
15
  "build": "tsc",
16
+ "test": "npm run build && node --test dist/test/**/*.test.js",
16
17
  "prepublishOnly": "npm run build"
17
18
  },
18
19
  "keywords": [
@@ -24,10 +25,10 @@
24
25
  ],
25
26
  "license": "MIT",
26
27
  "dependencies": {
27
- "openai": "^6.44.0"
28
+ "openai": "^4.0.0"
28
29
  },
29
30
  "devDependencies": {
30
- "@types/node": "^26.0.0",
31
- "typescript": "^6.0.3"
31
+ "@types/node": "^24.0.0",
32
+ "typescript": "^5.0.0"
32
33
  }
33
34
  }