@basedchef/contextkit 0.1.2 → 0.1.3

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  TypeScript SDK for ContextKit, a Bankr-hosted x402 context API for AI agents.
4
4
 
5
- Use it when you are building an advanced TypeScript integration that needs typed calls to ContextKit direct APIs, webhook verification, and optional x402 payment handling. For the simplest paid path, agents can call the Bankr-hosted x402 endpoints directly without this SDK.
5
+ Use it when you are building a TypeScript integration that needs typed calls to ContextKit direct APIs, webhook verification, API-key credits, and optional x402 payment handling. For the simplest paid path, agents can still call the Bankr-hosted x402 endpoints directly without this SDK.
6
6
 
7
7
  ## Install
8
8
 
@@ -18,7 +18,9 @@ npm install @basedchef/contextkit
18
18
  - Extract durable user profile memory.
19
19
  - Estimate tokens for API-key workflows.
20
20
  - Verify signed ContextKit webhook deliveries.
21
- - Attach API keys and optional x402 payment handlers for direct API integrations.
21
+ - Attach API keys for direct API integrations.
22
+ - Use account credits so SDK users can call paid endpoints without Bankr.
23
+ - Optionally attach an x402 payment handler when credits are not available.
22
24
 
23
25
  ## Quick Start
24
26
 
@@ -27,8 +29,7 @@ import { ContextKit } from "@basedchef/contextkit";
27
29
 
28
30
  const client = new ContextKit({
29
31
  apiKey: process.env.CONTEXTKIT_API_KEY!,
30
- baseUrl: "https://91.107.248.223.sslip.io",
31
- x402: async (challenge) => wallet.pay(challenge)
32
+ baseUrl: "https://91.107.248.223.sslip.io"
32
33
  });
33
34
 
34
35
  const response = await client.summarize({
@@ -50,6 +51,7 @@ await client.compressContext({ messages });
50
51
  await client.handoff({ messages });
51
52
  await client.extractProfile({ messages });
52
53
  await client.estimateTokens({ modelFamily: "openai", input: messages });
54
+ await client.credits();
53
55
  ```
54
56
 
55
57
  ## Bankr-Hosted x402 Path
@@ -66,7 +68,16 @@ That flow requires no ContextKit API key, no npm package, and no SDK.
66
68
 
67
69
  ## Direct API Path
68
70
 
69
- The SDK is for advanced integrations. Direct paid generation routes still require x402 payment. API keys are used for dashboard operations, analytics, webhook management, token estimates, and selected direct API routes.
71
+ The SDK is for direct API integrations. If the API key owner has ContextKit credits, paid generation routes run without Bankr and deduct the endpoint price from the account balance. If credits are insufficient, the API falls back to the standard x402 payment challenge.
72
+
73
+ ```ts
74
+ const client = new ContextKit({
75
+ apiKey: process.env.CONTEXTKIT_API_KEY!,
76
+ baseUrl: "https://91.107.248.223.sslip.io"
77
+ });
78
+ ```
79
+
80
+ Optional x402 fallback:
70
81
 
71
82
  ```ts
72
83
  const client = new ContextKit({
package/dist/index.cjs CHANGED
@@ -60,6 +60,20 @@ var ContextKit = class {
60
60
  async estimateTokens(input) {
61
61
  return this.post("/api/tokens/estimate", input);
62
62
  }
63
+ credits() {
64
+ return this.get("/api/auth/credits");
65
+ }
66
+ async get(path) {
67
+ const response = await this.fetcher(`${this.baseUrl.replace(/\/$/, "")}${path}`, {
68
+ headers: {
69
+ Authorization: `Bearer ${this.options.apiKey}`
70
+ }
71
+ });
72
+ if (response.ok) {
73
+ return await response.json();
74
+ }
75
+ throw new ContextKitError(response.status, await response.text());
76
+ }
63
77
  async post(path, body) {
64
78
  const url = `${this.baseUrl.replace(/\/$/, "")}${path}`;
65
79
  const init = {
package/dist/index.d.cts CHANGED
@@ -191,6 +191,23 @@ type MemoryEnrichmentResponse = {
191
191
  deprecatedMemories: string[];
192
192
  confidence: number;
193
193
  };
194
+ type CreditEvent = {
195
+ id: string;
196
+ ownerId: string;
197
+ type: "grant" | "debit" | "refund";
198
+ amountUsd: number;
199
+ balanceAfterUsd: number;
200
+ route?: string;
201
+ requestId?: string;
202
+ apiKeyId?: string;
203
+ note?: string;
204
+ createdAt: string;
205
+ };
206
+ type CreditsResponse = {
207
+ ownerId: string;
208
+ balanceUsd: number;
209
+ events: CreditEvent[];
210
+ };
194
211
  type X402PaymentHandler = (challenge: unknown, request: RequestInit & {
195
212
  url: string;
196
213
  }) => Promise<string>;
@@ -219,6 +236,8 @@ declare class ContextKit {
219
236
  compressedTokens: number;
220
237
  reductionPercent: number;
221
238
  }>;
239
+ credits(): Promise<CreditsResponse>;
240
+ private get;
222
241
  private post;
223
242
  }
224
243
  declare class ContextKitError extends Error {
@@ -253,4 +272,4 @@ declare function getFirstX402Requirement(challenge: X402Challenge): {
253
272
  };
254
273
  declare function encodeX402Payment(payment: unknown): string;
255
274
 
256
- export { type CompressContextResponse, ContextKit, ContextKitError, type ContextRequest, type ConversationMessage, type HandoffResponse, type MemoryEnrichmentResponse, type ProfileResponse, type SummarizeResponse, type X402PaymentHandler, encodeX402Payment, getFirstX402Requirement, verifyContextKitWebhook };
275
+ export { type CompressContextResponse, ContextKit, ContextKitError, type ContextRequest, type ConversationMessage, type CreditEvent, type CreditsResponse, type HandoffResponse, type MemoryEnrichmentResponse, type ProfileResponse, type SummarizeResponse, type X402PaymentHandler, encodeX402Payment, getFirstX402Requirement, verifyContextKitWebhook };
package/dist/index.d.ts CHANGED
@@ -191,6 +191,23 @@ type MemoryEnrichmentResponse = {
191
191
  deprecatedMemories: string[];
192
192
  confidence: number;
193
193
  };
194
+ type CreditEvent = {
195
+ id: string;
196
+ ownerId: string;
197
+ type: "grant" | "debit" | "refund";
198
+ amountUsd: number;
199
+ balanceAfterUsd: number;
200
+ route?: string;
201
+ requestId?: string;
202
+ apiKeyId?: string;
203
+ note?: string;
204
+ createdAt: string;
205
+ };
206
+ type CreditsResponse = {
207
+ ownerId: string;
208
+ balanceUsd: number;
209
+ events: CreditEvent[];
210
+ };
194
211
  type X402PaymentHandler = (challenge: unknown, request: RequestInit & {
195
212
  url: string;
196
213
  }) => Promise<string>;
@@ -219,6 +236,8 @@ declare class ContextKit {
219
236
  compressedTokens: number;
220
237
  reductionPercent: number;
221
238
  }>;
239
+ credits(): Promise<CreditsResponse>;
240
+ private get;
222
241
  private post;
223
242
  }
224
243
  declare class ContextKitError extends Error {
@@ -253,4 +272,4 @@ declare function getFirstX402Requirement(challenge: X402Challenge): {
253
272
  };
254
273
  declare function encodeX402Payment(payment: unknown): string;
255
274
 
256
- export { type CompressContextResponse, ContextKit, ContextKitError, type ContextRequest, type ConversationMessage, type HandoffResponse, type MemoryEnrichmentResponse, type ProfileResponse, type SummarizeResponse, type X402PaymentHandler, encodeX402Payment, getFirstX402Requirement, verifyContextKitWebhook };
275
+ export { type CompressContextResponse, ContextKit, ContextKitError, type ContextRequest, type ConversationMessage, type CreditEvent, type CreditsResponse, type HandoffResponse, type MemoryEnrichmentResponse, type ProfileResponse, type SummarizeResponse, type X402PaymentHandler, encodeX402Payment, getFirstX402Requirement, verifyContextKitWebhook };
package/dist/index.js CHANGED
@@ -30,6 +30,20 @@ var ContextKit = class {
30
30
  async estimateTokens(input) {
31
31
  return this.post("/api/tokens/estimate", input);
32
32
  }
33
+ credits() {
34
+ return this.get("/api/auth/credits");
35
+ }
36
+ async get(path) {
37
+ const response = await this.fetcher(`${this.baseUrl.replace(/\/$/, "")}${path}`, {
38
+ headers: {
39
+ Authorization: `Bearer ${this.options.apiKey}`
40
+ }
41
+ });
42
+ if (response.ok) {
43
+ return await response.json();
44
+ }
45
+ throw new ContextKitError(response.status, await response.text());
46
+ }
33
47
  async post(path, body) {
34
48
  const url = `${this.baseUrl.replace(/\/$/, "")}${path}`;
35
49
  const init = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basedchef/contextkit",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "TypeScript SDK for ContextKit, a Bankr-hosted x402 context API for AI agents, memory compression, handoffs, profiles, and webhooks.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",