@tangle-network/tcloud 0.1.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/LICENSE +190 -0
- package/README.md +354 -0
- package/dist/chunk-4AOQNUQ3.js +573 -0
- package/dist/chunk-YORNEPCU.js +49 -0
- package/dist/cli.cjs +895 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +273 -0
- package/dist/index.cjs +654 -0
- package/dist/index.d.cts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +20 -0
- package/dist/shielded-BRhsV-s-.d.cts +343 -0
- package/dist/shielded-BRhsV-s-.d.ts +343 -0
- package/dist/shielded.cjs +608 -0
- package/dist/shielded.d.cts +2 -0
- package/dist/shielded.d.ts +2 -0
- package/dist/shielded.js +12 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2024 Tangle Network
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
# tcloud
|
|
2
|
+
|
|
3
|
+
TypeScript SDK and CLI for [Tangle AI Cloud](https://tangleai.cloud) — decentralized LLM inference with operator routing, reputation-based selection, and anonymous payments via ShieldedCredits.
|
|
4
|
+
|
|
5
|
+
Zero framework dependencies. Pure `fetch` + SSE. Works in Node.js, Deno, Bun, and edge runtimes.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [SDK](#sdk)
|
|
11
|
+
- [Quick Start](#quick-start)
|
|
12
|
+
- [Model Selection](#model-selection)
|
|
13
|
+
- [Streaming](#streaming)
|
|
14
|
+
- [Full Chat Completion](#full-chat-completion)
|
|
15
|
+
- [Private Inference](#private-inference)
|
|
16
|
+
- [Operator Routing](#operator-routing)
|
|
17
|
+
- [Models and Operators](#models-and-operators)
|
|
18
|
+
- [API Key Management](#api-key-management)
|
|
19
|
+
- [Cost Estimation](#cost-estimation)
|
|
20
|
+
- [Spending Limits](#spending-limits)
|
|
21
|
+
- [CLI](#cli)
|
|
22
|
+
- [Authentication](#authentication)
|
|
23
|
+
- [Chat](#chat)
|
|
24
|
+
- [Browse](#browse)
|
|
25
|
+
- [Credits and Keys](#credits-and-keys)
|
|
26
|
+
- [Wallet Management](#wallet-management)
|
|
27
|
+
- [Configuration](#configuration)
|
|
28
|
+
- [OpenAI SDK Compatibility](#openai-sdk-compatibility)
|
|
29
|
+
- [Vercel AI SDK Compatibility](#vercel-ai-sdk-compatibility)
|
|
30
|
+
- [Examples](#examples)
|
|
31
|
+
- [License](#license)
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install tcloud
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or run the CLI directly:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx tcloud chat "What is Tangle?"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## SDK
|
|
46
|
+
|
|
47
|
+
### Quick Start
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { TCloud } from 'tcloud'
|
|
51
|
+
|
|
52
|
+
// Set model at client creation — explicit and consistent.
|
|
53
|
+
const client = new TCloud({
|
|
54
|
+
apiKey: 'sk-tan-...',
|
|
55
|
+
model: 'gpt-4o-mini',
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const answer = await client.ask('What is Tangle Network?')
|
|
59
|
+
console.log(answer)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Model Selection
|
|
63
|
+
|
|
64
|
+
Model is set at client creation. Override per-request when needed:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
// Default model for all requests
|
|
68
|
+
const client = new TCloud({ apiKey: '...', model: 'gpt-4o-mini' })
|
|
69
|
+
await client.ask('Hello') // uses gpt-4o-mini
|
|
70
|
+
|
|
71
|
+
// Full control per-request (OpenAI-compatible)
|
|
72
|
+
const completion = await client.chat({
|
|
73
|
+
model: 'claude-sonnet-4-6',
|
|
74
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
75
|
+
temperature: 0.5,
|
|
76
|
+
maxTokens: 100,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// Get full response with usage stats
|
|
80
|
+
const full = await client.askFull('Hello')
|
|
81
|
+
console.log(full.model, full.usage?.total_tokens)
|
|
82
|
+
|
|
83
|
+
// Search available models
|
|
84
|
+
const llamas = await client.searchModels('llama')
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Streaming
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
for await (const chunk of client.askStream('Explain zero-knowledge proofs')) {
|
|
91
|
+
process.stdout.write(chunk)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// With model override
|
|
95
|
+
for await (const chunk of client.askStream('Hello', 'claude-sonnet-4-6')) {
|
|
96
|
+
process.stdout.write(chunk)
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Full Chat Completion
|
|
101
|
+
|
|
102
|
+
OpenAI-compatible request/response format:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const completion = await client.chat({
|
|
106
|
+
model: 'meta-llama/llama-4-maverick',
|
|
107
|
+
messages: [
|
|
108
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
109
|
+
{ role: 'user', content: 'Hello' },
|
|
110
|
+
],
|
|
111
|
+
temperature: 0.7,
|
|
112
|
+
maxTokens: 1024,
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
console.log(completion.choices[0].message.content)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Private Inference
|
|
119
|
+
|
|
120
|
+
Anonymous inference with no API key. Uses EIP-712 SpendAuth signatures — the operator verifies payment without learning your identity.
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { TCloud } from 'tcloud'
|
|
124
|
+
|
|
125
|
+
const client = TCloud.shielded()
|
|
126
|
+
const answer = await client.ask('Hello from the shadows')
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Under the hood: generates an ephemeral wallet, signs a SpendAuth payload, and sends it as an `X-Payment-Signature` header. The operator validates the cryptographic proof and serves inference without knowing who you are.
|
|
130
|
+
|
|
131
|
+
### Operator Routing
|
|
132
|
+
|
|
133
|
+
Route requests to specific operators or use strategy-based selection:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const client = new TCloud({
|
|
137
|
+
apiKey: 'sk-tan-...',
|
|
138
|
+
routing: {
|
|
139
|
+
prefer: 'operator-slug', // specific operator
|
|
140
|
+
strategy: 'lowest-latency', // or 'lowest-price', 'highest-reputation'
|
|
141
|
+
region: 'us-east', // geographic preference
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The gateway selects the best operator based on a composite score (reputation 40%, latency 30%, price 30%) and returns the selection in response headers:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
// After a request, check which operator served it:
|
|
150
|
+
// X-Tangle-Operator: <slug>
|
|
151
|
+
// X-Tangle-Price-Input: <per-token>
|
|
152
|
+
// X-Tangle-Price-Output: <per-token>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Models and Operators
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
// List all available models
|
|
159
|
+
const models = await client.models()
|
|
160
|
+
models.forEach(m => console.log(m.id, m._provider))
|
|
161
|
+
|
|
162
|
+
// Search models by name, provider, or capability
|
|
163
|
+
const llamas = await client.searchModels('llama')
|
|
164
|
+
const anthropic = await client.searchModels('anthropic')
|
|
165
|
+
|
|
166
|
+
// List active operators with stats
|
|
167
|
+
const { operators, stats } = await client.operators()
|
|
168
|
+
console.log(`${stats.activeOperators} operators serving ${stats.totalModels} models`)
|
|
169
|
+
|
|
170
|
+
// Check credit balance
|
|
171
|
+
const credits = await client.credits()
|
|
172
|
+
console.log(`Balance: $${credits.balance}`)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### API Key Management
|
|
176
|
+
|
|
177
|
+
Create, list, and revoke API keys programmatically:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
// Create a new key
|
|
181
|
+
const { key, id } = await client.createKey('my-app')
|
|
182
|
+
console.log(key) // sk-tan-... (shown once, store it)
|
|
183
|
+
|
|
184
|
+
// List all keys
|
|
185
|
+
const keys = await client.keys()
|
|
186
|
+
keys.forEach(k => console.log(k.name, k.prefix, k.lastUsedAt))
|
|
187
|
+
|
|
188
|
+
// Revoke a key
|
|
189
|
+
await client.revokeKey(id)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Cost Estimation
|
|
193
|
+
|
|
194
|
+
Preview cost before sending a request:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
const cost = await client.estimateCost({
|
|
198
|
+
model: 'gpt-4o',
|
|
199
|
+
inputTokens: 1000,
|
|
200
|
+
outputTokens: 500,
|
|
201
|
+
})
|
|
202
|
+
console.log(`Estimated: $${cost.total.toFixed(6)}`)
|
|
203
|
+
// { inputCost: 0.005, outputCost: 0.0075, total: 0.0125 }
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Spending Limits
|
|
207
|
+
|
|
208
|
+
Prevent runaway costs with per-request and total budget caps:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
const client = new TCloud({
|
|
212
|
+
apiKey: 'sk-tan-...',
|
|
213
|
+
model: 'gpt-4o-mini',
|
|
214
|
+
limits: {
|
|
215
|
+
maxCostPerRequest: 0.01, // $0.01 max per request
|
|
216
|
+
maxTotalSpend: 1.00, // $1.00 lifetime budget
|
|
217
|
+
maxRequests: 100, // hard request cap
|
|
218
|
+
onLimitWarning: (info) => {
|
|
219
|
+
console.warn(`${info.type} at ${info.current}/${info.limit}`)
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
// Requests that would exceed limits are blocked with TCloudError (429)
|
|
225
|
+
await client.ask('Hello')
|
|
226
|
+
|
|
227
|
+
// Check metering
|
|
228
|
+
const { totalSpent, requestCount } = client.usage
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## CLI
|
|
232
|
+
|
|
233
|
+
### Authentication
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
tcloud auth login # Browser-based device flow
|
|
237
|
+
tcloud auth set-key sk-tan-... # Set key directly
|
|
238
|
+
tcloud auth status # Check current auth
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Chat
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
tcloud chat "Explain zero-knowledge proofs"
|
|
245
|
+
tcloud chat -m meta-llama/llama-4-maverick "Hello"
|
|
246
|
+
tcloud chat --private "Anonymous request" # ShieldedCredits mode
|
|
247
|
+
tcloud chat # Interactive mode
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Browse
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
tcloud models # List available models
|
|
254
|
+
tcloud models -s llama # Search models
|
|
255
|
+
tcloud operators # List active operators
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Credits and Keys
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
tcloud credits balance # Check balance
|
|
262
|
+
tcloud credits add 10 # Add credits
|
|
263
|
+
tcloud keys create my-app # Create a new API key
|
|
264
|
+
tcloud keys list # List keys
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Wallet Management
|
|
268
|
+
|
|
269
|
+
For private inference, manage ephemeral wallets:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
tcloud wallet generate # Create wallet
|
|
273
|
+
tcloud wallet generate -l "research" # With label
|
|
274
|
+
tcloud wallet list # List wallets
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Wallets use BIP-39 mnemonics with BIP-44 derivation. Private keys are encrypted at rest with AES-256-GCM (PBKDF2 210K iterations).
|
|
278
|
+
|
|
279
|
+
## Configuration
|
|
280
|
+
|
|
281
|
+
Config stored in `~/.tcloud/config.json`:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
tcloud config --api-url https://api.tangleai.cloud
|
|
285
|
+
tcloud config --model gpt-4o-mini
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Environment variables:
|
|
289
|
+
- `TCLOUD_API_KEY` — API key (primary)
|
|
290
|
+
- `OPENAI_API_KEY` — Fallback API key (works because the API is OpenAI-compatible)
|
|
291
|
+
- `TCLOUD_BASE_URL` — Override API base URL
|
|
292
|
+
|
|
293
|
+
## OpenAI SDK Compatibility
|
|
294
|
+
|
|
295
|
+
tcloud's API is OpenAI-compatible. You can use the OpenAI SDK directly:
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
import OpenAI from 'openai'
|
|
299
|
+
|
|
300
|
+
const client = new OpenAI({
|
|
301
|
+
apiKey: 'sk-tan-...',
|
|
302
|
+
baseURL: 'https://api.tangleai.cloud/v1',
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
const completion = await client.chat.completions.create({
|
|
306
|
+
model: 'meta-llama/llama-4-maverick',
|
|
307
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
308
|
+
})
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Vercel AI SDK Compatibility
|
|
312
|
+
|
|
313
|
+
Use with the Vercel AI SDK's OpenAI provider:
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
import { createOpenAI } from '@ai-sdk/openai'
|
|
317
|
+
import { generateText } from 'ai'
|
|
318
|
+
|
|
319
|
+
const tangle = createOpenAI({
|
|
320
|
+
apiKey: 'sk-tan-...',
|
|
321
|
+
baseURL: 'https://api.tangleai.cloud/v1',
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
const { text } = await generateText({
|
|
325
|
+
model: tangle('meta-llama/llama-4-maverick'),
|
|
326
|
+
prompt: 'What is decentralized AI?',
|
|
327
|
+
})
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Examples
|
|
331
|
+
|
|
332
|
+
See the [`examples/`](./examples/) directory — each is a self-contained script:
|
|
333
|
+
|
|
334
|
+
| # | Example | What it shows |
|
|
335
|
+
|---|---------|---------------|
|
|
336
|
+
| 01 | [Quick Start](./examples/01-quick-start.ts) | Minimum viable setup |
|
|
337
|
+
| 02 | [Model Selection](./examples/02-model-selection.ts) | Three ways to pick a model, search, browse |
|
|
338
|
+
| 03 | [Streaming](./examples/03-streaming.ts) | Real-time SSE output, text + chunk modes |
|
|
339
|
+
| 04 | [Private Inference](./examples/04-private-inference.ts) | ShieldedCredits, ephemeral wallets, auto-replenish |
|
|
340
|
+
| 05 | [Operator Routing](./examples/05-operator-routing.ts) | Prefer operator, strategy, region, list operators |
|
|
341
|
+
| 06 | [Cost & Usage](./examples/06-cost-and-usage.ts) | Estimate cost, track tokens, check balance |
|
|
342
|
+
| 07 | [API Keys](./examples/07-api-keys.ts) | Create, list, revoke keys programmatically |
|
|
343
|
+
| 08 | [OpenAI SDK](./examples/08-openai-compat.ts) | Drop-in replacement via baseURL |
|
|
344
|
+
| 09 | [Vercel AI SDK](./examples/09-vercel-ai-sdk.ts) | generateText + streamText with Tangle |
|
|
345
|
+
| 10 | [Spending Limits](./examples/10-spending-limits.ts) | Budget caps, request limits, warning callbacks |
|
|
346
|
+
|
|
347
|
+
Run any example:
|
|
348
|
+
```bash
|
|
349
|
+
TCLOUD_API_KEY=sk-tan-... npx tsx examples/01-quick-start.ts
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## License
|
|
353
|
+
|
|
354
|
+
[Apache-2.0](./LICENSE)
|