@base44-preview/sdk 0.8.39-pr.231.1187092 → 0.8.39-pr.232.affea8a

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.
@@ -1,13 +1,13 @@
1
1
  /**
2
- * Connection details for the Base44 AI Gateway.
2
+ * A connection to the Base44 AI Gateway.
3
+ *
4
+ * Contains the base URL and bearer token to use with any OpenAI-compatible
5
+ * client pointed at the Base44 AI Gateway.
3
6
  */
4
7
  export interface AiGatewayConnection {
5
- /** Base URL of the gateway's OpenAI-compatible Chat Completions endpoint. */
8
+ /** Base URL of the gateway's OpenAI-compatible endpoint. */
6
9
  baseURL: string;
7
- /**
8
- * Bearer token that authenticates the request. Empty string when the caller is
9
- * unauthenticated.
10
- */
10
+ /** Bearer token used to authenticate requests to the gateway. */
11
11
  token: string;
12
12
  }
13
13
  /**
@@ -25,48 +25,13 @@ export interface AiGatewayModuleConfig {
25
25
  /**
26
26
  * AI Gateway module for calling Base44's managed AI models from your own code.
27
27
  *
28
- * `connection()` hands you a `baseURL` and `token` that authenticate as your
29
- * Base44 app. An OpenAI-compatible client is any library, such as the `openai`
30
- * SDK or the Vercel AI SDK, that has the same request and response format
31
- * as OpenAI's Chat Completions API and lets you point it at a custom `baseURL`
32
- * instead of OpenAI's own servers. Pass `connection()`'s values to one of
33
- * these clients and it works against Base44's gateway exactly as it would
34
- * against the provider directly, no separate account, API key, or billing
35
- * setup with the underlying model provider required.
36
- *
37
- * Call `connection()` from a backend function rather than the browser. That's
38
- * where your instructions, tools, and business logic stay server-side, where
39
- * users can't inspect or tamper with them, and where you can enforce your own
40
- * auth checks, rate limits, or spend limits around the call. `token` is the
41
- * caller's own session token, the same one the SDK already uses for every
42
- * other call, so calling from the browser doesn't expose anything new.
43
- *
44
- * ## Models
45
- *
46
- * Build AI agents or call models directly from your app's backend functions.
47
- * Pass `'automatic'` to let Base44 choose a model, or pin a specific one such
48
- * as `'claude_sonnet_4_6'`, `'claude_opus_4_8'`, `'gpt_5_5'`, or
49
- * `'gemini_3_1_pro'`.
50
- *
51
- * See the [`model` options on `InvokeLLM`](/developers/references/sdk/docs/type-aliases/integrations#invokellm)
52
- * for the current set of models you can use.
53
- *
54
- * ## Authentication Modes
55
- *
56
- * This module is available to use with a client in all authentication modes:
57
- *
58
- * - **Anonymous or User authentication** (`base44.aiGateway`): The gateway connection is scoped to the current user's permissions.
59
- * - **Service role authentication** (`base44.asServiceRole.aiGateway`): The gateway connection uses the service role for backend code that needs elevated permissions.
60
- *
61
- * ## Billing and limits
28
+ * The gateway exposes an OpenAI-compatible Chat Completions endpoint, so any
29
+ * OpenAI-compatible SDK works against it:
30
+ * - Build custom AI agents or call models directly from your backend code
31
+ * - Uses your app's models, billing, and credit quota, no API key to manage
62
32
  *
63
- * Requests are billed to your app's credit quota, which is the same shared
64
- * quota your app's built-in AI features use, and isn't split per user. If the
65
- * app runs out of credits, the gateway stops working for every user of the
66
- * app until the quota resets. A request is rejected before the model runs if
67
- * the app is out of credits.
68
- *
69
- * Streaming responses aren't supported yet, so leave `stream` unset on your requests.
33
+ * Available in user authentication mode (`base44.aiGateway`) and with the
34
+ * service-role token via `base44.asServiceRole.aiGateway`.
70
35
  */
71
36
  export interface AiGatewayModule {
72
37
  /**
@@ -74,36 +39,19 @@ export interface AiGatewayModule {
74
39
  *
75
40
  * Returns the `baseURL` and `token` to pass to any OpenAI-compatible client.
76
41
  *
77
- * @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
78
- *
79
- * @example
80
- * ```typescript
81
- * // Call a model directly with the OpenAI SDK, inside a backend function
82
- * import { createClientFromRequest } from "@base44/sdk";
83
- * import OpenAI from "openai";
42
+ * The `token` is the current caller's bearer token: the app user's token for
43
+ * `base44.aiGateway`, or the service-role token for `base44.asServiceRole.aiGateway`.
44
+ * When the caller is unauthenticated, `token` is an empty string.
84
45
  *
85
- * const base44 = createClientFromRequest(request);
86
- * const { baseURL, token } = base44.aiGateway.connection();
87
- * const openai = new OpenAI({ baseURL, apiKey: token });
88
- *
89
- * const response = await openai.chat.completions.create({
90
- * model: "automatic",
91
- * messages: [{ role: "user", content: "Summarize this week's top support tickets." }],
92
- * });
93
- *
94
- * console.log(response.choices[0].message.content);
95
- * ```
46
+ * @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
96
47
  *
97
48
  * @example
98
49
  * ```typescript
99
- * // Review a return request with a tool-using agent, inside a backend function
100
- * import { createClientFromRequest } from "@base44/sdk";
101
50
  * import { ToolLoopAgent, tool, stepCountIs, hasToolCall } from "ai";
102
51
  * import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
103
52
  * import { z } from "zod";
104
53
  *
105
- * const base44 = createClientFromRequest(request);
106
- * const returnRequest = await base44.entities.ReturnRequest.get(returnId);
54
+ * const request = await base44.entities.ReturnRequest.get(returnId);
107
55
  * const { baseURL, token } = base44.aiGateway.connection();
108
56
  * // Point any OpenAI-compatible client at `baseURL` with `apiKey: token`.
109
57
  * const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token });
@@ -118,7 +66,7 @@ export interface AiGatewayModule {
118
66
  * description: "This customer's past orders, optionally filtered by status",
119
67
  * inputSchema: z.object({ status: z.string().optional() }),
120
68
  * execute: ({ status }) => {
121
- * const query = { customer_email: returnRequest.customer_email };
69
+ * const query = { customer_email: request.customer_email };
122
70
  * if (status) query.status = status;
123
71
  * return base44.entities.Order.filter(query, "-created_date", 50);
124
72
  * },
@@ -133,7 +81,7 @@ export interface AiGatewayModule {
133
81
  * stopWhen: [stepCountIs(8), hasToolCall("submitVerdict")],
134
82
  * });
135
83
  *
136
- * await agent.generate({ prompt: `Review this return request: ${JSON.stringify(returnRequest)}` });
84
+ * await agent.generate({ prompt: `Review this return request: ${JSON.stringify(request)}` });
137
85
  * ```
138
86
  */
139
87
  connection(): AiGatewayConnection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.39-pr.231.1187092",
3
+ "version": "0.8.39-pr.232.affea8a",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",