@orth/sdk 0.5.0 → 0.5.1

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.
Files changed (2) hide show
  1. package/README.md +157 -24
  2. package/package.json +4 -2
package/README.md CHANGED
@@ -1,11 +1,48 @@
1
- # @orth/sdk
1
+ <div align="center">
2
2
 
3
- TypeScript SDK to call any API on the Orthogonal platform.
3
+ # Orthogonal SDK
4
+
5
+ **Call any API on the [Orthogonal](https://orthogonal.com) platform from TypeScript — one client, one balance.**
6
+
7
+ Reach hundreds of production APIs through a single client and a single credit balance. No per-provider signups, keys, or contracts — authentication, routing, and billing are handled for you.
8
+
9
+ [![npm version](https://img.shields.io/npm/v/@orth/sdk.svg?logo=npm&color=cb3837)](https://www.npmjs.com/package/@orth/sdk)
10
+ [![npm downloads](https://img.shields.io/npm/dm/@orth/sdk.svg?color=cb3837)](https://www.npmjs.com/package/@orth/sdk)
11
+ [![types](https://img.shields.io/npm/types/@orth/sdk.svg?logo=typescript&color=3178c6)](https://www.npmjs.com/package/@orth/sdk)
12
+ [![node](https://img.shields.io/node/v/@orth/sdk.svg?logo=node.js&color=339933)](https://nodejs.org)
13
+ [![license](https://img.shields.io/npm/l/@orth/sdk.svg?color=blue)](./LICENSE)
14
+
15
+ </div>
16
+
17
+ ## Table of Contents
18
+
19
+ - [Why Orthogonal](#why-orthogonal)
20
+ - [Installation](#installation)
21
+ - [Quick Start](#quick-start)
22
+ - [Authentication](#authentication)
23
+ - [Usage](#usage)
24
+ - [Error Handling](#error-handling)
25
+ - [API Reference](#api-reference)
26
+ - [TypeScript](#typescript)
27
+ - [Related](#related)
28
+ - [License](#license)
29
+
30
+ ## Why Orthogonal
31
+
32
+ Orthogonal is a marketplace of production APIs behind one account and one balance:
33
+
34
+ - **One integration** — call any API on the platform through a single `run()` method.
35
+ - **Pay per use** — a single credit balance instead of juggling dozens of provider subscriptions.
36
+ - **Self-correcting errors** — failed calls carry a structured hint (expected schema, unexpected/missing fields, numeric bounds) so agents can fix and retry.
37
+ - **Fully typed** — ships with TypeScript definitions and ESM + CJS builds.
4
38
 
5
39
  ## Installation
6
40
 
41
+ Requires **Node.js 18+**.
42
+
7
43
  ```bash
8
44
  npm install @orth/sdk
45
+ # or: pnpm add @orth/sdk / yarn add @orth/sdk
9
46
  ```
10
47
 
11
48
  ## Quick Start
@@ -14,41 +51,137 @@ npm install @orth/sdk
14
51
  import Orthogonal from "@orth/sdk";
15
52
 
16
53
  const orthogonal = new Orthogonal({
17
- apiKey: process.env.ORTHOGONAL_API_KEY,
54
+ apiKey: process.env.ORTHOGONAL_API_KEY!,
18
55
  });
19
56
 
20
- const response = await orthogonal.run({
21
- api: "andi",
22
- path: "/api/v1/search",
23
- query: { q: "what is the weather today" },
57
+ const res = await orthogonal.run({
58
+ api: "tavily",
59
+ path: "/search",
60
+ query: { query: "latest AI news" },
24
61
  });
25
62
 
26
- console.log(response.data);
27
- console.log(response.price); // e.g., "0.01"
63
+ console.log(res.data); // the upstream API's response
64
+ console.log(res.price); // amount charged, e.g. "0.01"
28
65
  ```
29
66
 
30
- ## Response
67
+ Get an API key from your [Orthogonal dashboard](https://orthogonal.com/dashboard).
31
68
 
32
- ### Success
69
+ ## Authentication
33
70
 
34
- ```json
35
- {
36
- "success": true,
37
- "price": "0.01",
38
- "data": { ... }
39
- }
71
+ Pass your key to the constructor:
72
+
73
+ ```typescript
74
+ const orthogonal = new Orthogonal({ apiKey: "orth_live_your_key" });
40
75
  ```
41
76
 
42
- ### Error
77
+ Prefer reading it from the environment so keys never live in source:
78
+
79
+ ```typescript
80
+ const orthogonal = new Orthogonal({ apiKey: process.env.ORTHOGONAL_API_KEY! });
81
+ ```
82
+
83
+ ## Usage
84
+
85
+ ### GET request (query params)
86
+
87
+ ```typescript
88
+ const res = await orthogonal.run({
89
+ api: "fantastic-jobs",
90
+ path: "/v1/active-ats",
91
+ query: { time_frame: "1h", limit: 10 },
92
+ });
93
+ ```
94
+
95
+ ### POST request (JSON body)
96
+
97
+ ```typescript
98
+ const res = await orthogonal.run({
99
+ api: "some-api",
100
+ path: "/v1/generate",
101
+ body: { prompt: "a red bicycle" },
102
+ });
103
+ ```
43
104
 
44
- ```json
45
- {
46
- "success": false,
47
- "price": "0",
48
- "error": "API my-api not found or not active"
105
+ ### Custom headers
106
+
107
+ Headers passed to the constructor are sent on every request:
108
+
109
+ ```typescript
110
+ const orthogonal = new Orthogonal({
111
+ apiKey: process.env.ORTHOGONAL_API_KEY!,
112
+ headers: { "x-my-trace-id": "abc123" },
113
+ });
114
+ ```
115
+
116
+ ## Error Handling
117
+
118
+ `run()` resolves with the response on success and **throws** an `OrthogonalRunError` on any non-2xx response. The error extends `Error` (so `error.message` and `instanceof Error` work) and carries structured details:
119
+
120
+ ```typescript
121
+ import Orthogonal, { OrthogonalRunError } from "@orth/sdk";
122
+
123
+ try {
124
+ const res = await orthogonal.run({
125
+ api: "fantastic-jobs",
126
+ path: "/v1/active-ats",
127
+ query: { time_frame: "1h", company: "Google" }, // wrong field name
128
+ });
129
+ } catch (err) {
130
+ if (err instanceof OrthogonalRunError) {
131
+ console.error(err.message); // human-readable summary
132
+ console.error(err.status); // HTTP status, e.g. 400
133
+ console.error(err.orthogonal); // self-correction hint (see below)
134
+ console.error(err.responseBody); // full parsed error body
135
+ }
49
136
  }
50
137
  ```
51
138
 
139
+ On a contract violation the `orthogonal` hint tells you exactly what to fix — for example, that `company` is an unexpected field and `organization` is the expected one, plus the endpoint's expected schema — so an agent can correct the request and retry instead of repeating a failing call.
140
+
141
+ ## API Reference
142
+
143
+ ### `new Orthogonal(config)`
144
+
145
+ | Option | Type | Description |
146
+ | --- | --- | --- |
147
+ | `apiKey` | `string` | **Required.** Your Orthogonal API key (`orth_live_…` / `orth_test_…`). |
148
+ | `headers` | `Record<string, string>` | Optional headers sent on every request. |
149
+
150
+ ### `orthogonal.run(options)` → `Promise<RunResponse>`
151
+
152
+ | Option | Type | Description |
153
+ | --- | --- | --- |
154
+ | `api` | `string` | **Required.** The API slug (e.g. `"tavily"`). |
155
+ | `path` | `string` | **Required.** The endpoint path (e.g. `"/search"`). |
156
+ | `query` | `Record<string, unknown>` | Query parameters. |
157
+ | `body` | `Record<string, unknown>` | Request body for POST/PUT/PATCH. |
158
+
159
+ **`RunResponse`**
160
+
161
+ | Field | Type | Description |
162
+ | --- | --- | --- |
163
+ | `success` | `boolean` | Whether the call succeeded. |
164
+ | `price` | `string` | Amount charged in USD (e.g. `"0.01"`). |
165
+ | `data` | `unknown` | The upstream API's response. |
166
+
167
+ ### `OrthogonalRunError`
168
+
169
+ Thrown by `run()` on a non-2xx response. Extends `Error`.
170
+
171
+ | Property | Type | Description |
172
+ | --- | --- | --- |
173
+ | `status` | `number` | HTTP status of the failed response. |
174
+ | `orthogonal` | `unknown` | Self-correction hint (expected schema, unexpected/missing fields), when present. |
175
+ | `responseBody` | `unknown` | The full parsed response body. |
176
+
177
+ ## TypeScript
178
+
179
+ The package ships with type definitions and both ESM and CommonJS builds — no `@types` package needed. All options and responses (`OrthogonalConfig`, `RunOptions`, `RunResponse`) are exported.
180
+
181
+ ## Related
182
+
183
+ - **[`@orth/cli`](https://www.npmjs.com/package/@orth/cli)** — the Orthogonal command-line tool for discovering and calling APIs from your terminal.
184
+
52
185
  ## License
53
186
 
54
- MIT
187
+ [MIT](./LICENSE) © Orthogonal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orth/sdk",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "TypeScript SDK to call any API on the Orthogonal platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -13,7 +13,9 @@
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
17
19
  ],
18
20
  "sideEffects": false,
19
21
  "scripts": {