Skip to content

Commit ac4b657

Browse files
committed
docs(ai-gateway): fix review feedback on rationale and examples
Correct the misleading security claim that calling from a backend function keeps the token out of the browser — it's the same session token already used for every other SDK call. The real reason to use a backend function is code integrity: your instructions, tools, and business logic stay server-side where you can enforce your own auth, rate, and spend limits. Also show where the base44 client comes from in both examples (createClientFromRequest), instead of using a bare base44 with no indication of its origin.
1 parent 886e314 commit ac4b657

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/modules/ai-gateway.types.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ export interface AiGatewayModuleConfig {
3737
* setup with the underlying model provider required.
3838
*
3939
* Call `connection()` from a backend function rather than the browser. That's
40-
* where you can wire tools that read and write your app's own entities and
41-
* business logic without shipping that logic to the client. It also keeps the
42-
* gateway token out of the browser, where it could be stolen and used to
43-
* spend against your app's shared credit quota.
40+
* where your instructions, tools, and business logic stay server-side, where
41+
* users can't inspect or tamper with them, and where you can enforce your own
42+
* auth checks, rate limits, or spend limits around the call. `token` is the
43+
* caller's own session token, the same one the SDK already uses for every
44+
* other call, so calling from the browser doesn't expose anything new.
4445
*
4546
* ## Models
4647
*
@@ -80,8 +81,10 @@ export interface AiGatewayModule {
8081
* @example
8182
* ```typescript
8283
* // Call a model directly with the OpenAI SDK, inside a backend function
84+
* import { createClientFromRequest } from "@base44/sdk";
8385
* import OpenAI from "openai";
8486
*
87+
* const base44 = createClientFromRequest(request);
8588
* const { baseURL, token } = base44.aiGateway.connection();
8689
* const openai = new OpenAI({ baseURL, apiKey: token });
8790
*
@@ -96,11 +99,13 @@ export interface AiGatewayModule {
9699
* @example
97100
* ```typescript
98101
* // Review a return request with a tool-using agent, inside a backend function
102+
* import { createClientFromRequest } from "@base44/sdk";
99103
* import { ToolLoopAgent, tool, stepCountIs, hasToolCall } from "ai";
100104
* import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
101105
* import { z } from "zod";
102106
*
103-
* const request = await base44.entities.ReturnRequest.get(returnId);
107+
* const base44 = createClientFromRequest(request);
108+
* const returnRequest = await base44.entities.ReturnRequest.get(returnId);
104109
* const { baseURL, token } = base44.aiGateway.connection();
105110
* // Point any OpenAI-compatible client at `baseURL` with `apiKey: token`.
106111
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token });
@@ -115,7 +120,7 @@ export interface AiGatewayModule {
115120
* description: "This customer's past orders, optionally filtered by status",
116121
* inputSchema: z.object({ status: z.string().optional() }),
117122
* execute: ({ status }) => {
118-
* const query = { customer_email: request.customer_email };
123+
* const query = { customer_email: returnRequest.customer_email };
119124
* if (status) query.status = status;
120125
* return base44.entities.Order.filter(query, "-created_date", 50);
121126
* },
@@ -130,7 +135,7 @@ export interface AiGatewayModule {
130135
* stopWhen: [stepCountIs(8), hasToolCall("submitVerdict")],
131136
* });
132137
*
133-
* await agent.generate({ prompt: `Review this return request: ${JSON.stringify(request)}` });
138+
* await agent.generate({ prompt: `Review this return request: ${JSON.stringify(returnRequest)}` });
134139
* ```
135140
*/
136141
connection(): AiGatewayConnection;

0 commit comments

Comments
 (0)