|
| 1 | +/** |
| 2 | + * A connection to the Base44 AI Gateway. |
| 3 | + * |
| 4 | + * Contains the base URL and bearer token to use with any OpenAI-compatible client |
| 5 | + * (the OpenAI SDK, Mastra, and others) pointed at the Base44 AI Gateway. |
| 6 | + */ |
| 7 | +export interface GatewayConnection { |
| 8 | + /** Base URL of the gateway's OpenAI-compatible endpoint. */ |
| 9 | + baseURL: string; |
| 10 | + /** Bearer token used to authenticate requests to the gateway. */ |
| 11 | + token: string; |
| 12 | +} |
| 13 | + |
| 14 | +/** |
| 15 | + * Configuration for the AI Gateway module. |
| 16 | + * @internal |
| 17 | + */ |
| 18 | +export interface AiGatewayModuleConfig { |
| 19 | + /** Server URL */ |
| 20 | + serverUrl?: string; |
| 21 | + /** Authentication token */ |
| 22 | + token?: string; |
| 23 | +} |
| 24 | + |
| 25 | +/** |
| 26 | + * The AI Gateway module. |
| 27 | + * |
| 28 | + * Exposes the connection details for the Base44 AI Gateway so you can call it from |
| 29 | + * your own code using any OpenAI-compatible SDK — for example, to build a custom |
| 30 | + * agent on top of the gateway. |
| 31 | + */ |
| 32 | +export interface AiGatewayModule { |
| 33 | + /** |
| 34 | + * Gets the connection details for the Base44 AI Gateway. |
| 35 | + * |
| 36 | + * Returns the `baseURL` and `token` to pass to any OpenAI-compatible client (the |
| 37 | + * OpenAI SDK, Mastra, and others), so you can call the gateway from your own code |
| 38 | + * without constructing the URL or handling the token yourself. |
| 39 | + * |
| 40 | + * The `token` is the current caller's bearer token: the app user's token for |
| 41 | + * `base44.aiGateway`, or the service-role token for `base44.asServiceRole.aiGateway`. |
| 42 | + * |
| 43 | + * @returns The gateway {@linkcode GatewayConnection | connection} (`baseURL` and `token`). |
| 44 | + * |
| 45 | + * @example |
| 46 | + * ```typescript |
| 47 | + * // Inside a backend function, call the gateway with any OpenAI-compatible SDK |
| 48 | + * import { createClientFromRequest } from 'npm:@base44/sdk'; |
| 49 | + * import OpenAI from 'npm:openai'; |
| 50 | + * |
| 51 | + * Deno.serve(async (req) => { |
| 52 | + * const base44 = createClientFromRequest(req); |
| 53 | + * const { baseURL, token } = base44.aiGateway.connection(); |
| 54 | + * |
| 55 | + * const openai = new OpenAI({ baseURL, apiKey: token }); |
| 56 | + * const res = await openai.chat.completions.create({ |
| 57 | + * model: 'claude_sonnet_4_6', |
| 58 | + * messages: [{ role: 'user', content: 'Hello!' }], |
| 59 | + * }); |
| 60 | + * return Response.json({ text: res.choices[0].message.content }); |
| 61 | + * }); |
| 62 | + * ``` |
| 63 | + */ |
| 64 | + connection(): GatewayConnection; |
| 65 | +} |
0 commit comments