Skip to content

fix(ai-gateway): resolve gateway by app id in the path - #226

Merged
yardend-wix merged 3 commits into
mainfrom
fix/ai-gateway-app-id-route
Jul 12, 2026
Merged

fix(ai-gateway): resolve gateway by app id in the path#226
yardend-wix merged 3 commits into
mainfrom
fix/ai-gateway-app-id-route

Conversation

@yardend-wix

@yardend-wix yardend-wix commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Why

base44.aiGateway.connection() built the domain-routed gateway URL:

baseURL: `${serverUrl}/api/ai/openai/v1`

That endpoint resolves the app from the request Host. But in the browser the SDK targets the shared platform host (serverUrl defaults to https://base44.app), so when a backend function calls the gateway, the injected Base44-Api-Url is that shared host — the call lands on a host that resolves to no app and 404s ("App not found for this domain").

@claude

claude Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

yardend-wix and others added 2 commits July 9, 2026 16:02
connection() built the domain-routed gateway URL (${serverUrl}/api/ai/openai/v1),
which requires the request Host to resolve the app. In the browser the SDK
targets the shared host, so a backend function's gateway call lands on a host
that resolves to no app and 404s ("App not found for this domain").

Build the app_id-routed URL instead (${serverUrl}/api/apps/${appId}/ai/openai/v1),
matching how every other runtime module (entities, functions, connectors,
analytics, ...) places appId in the path. The gateway then resolves the app
from the URL regardless of which host the request came in on.

Pairs with the backend app_id mount in base44-dev/apper#15443.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…party SDKs

Replace the Mastra and OpenAI-SDK examples with a single minimal example
showing the connection() -> { baseURL, token } handoff against the
OpenAI-compatible Chat Completions endpoint, and drop specific library names
from the module prose. Keeps the docs client-agnostic ("any OpenAI-compatible
client") instead of pinning third-party SDKs/versions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yardend-wix
yardend-wix force-pushed the fix/ai-gateway-app-id-route branch from 4f6024f to ee4d816 Compare July 9, 2026 13:03
@claude

claude Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.8.37-pr.226.49a8ffd

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.37-pr.226.49a8ffd"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.8.37-pr.226.49a8ffd"
  }
}

Preview published to npm registry — try new features instantly!

…aw fetch

Replace the bare fetch example with a compact ToolLoopAgent — a background
action triggered on a record, with tools that carry input schemas and a finish
tool — matching the SDK's house example style (no Deno/npm: scaffolding).
Keeps the "point any OpenAI-compatible client at baseURL/token" note.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@claude

claude Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

@yardend-wix
yardend-wix merged commit c2b9f8e into main Jul 12, 2026
5 of 7 checks passed
@yardend-wix
yardend-wix deleted the fix/ai-gateway-app-id-route branch July 12, 2026 08:34
wixysam pushed a commit that referenced this pull request Jul 28, 2026
* docs(ai-gateway): publish AI Gateway module reference

The AI Gateway module's JSDoc was already updated in #226, but the types
were never added to the docs pipeline whitelist, so the module never
appeared in the generated SDK reference. Add AiGatewayModule and
AiGatewayConnection to the docs pipeline, and rewrite the JSDoc for
reference quality: explain what an OpenAI-compatible client is, clarify
that the credit quota is shared across all app users (not per-user),
link to the current model list, and split the growing intro into
Models / Authentication Modes / Billing and limits sections.

* 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.

* docs(ai-gateway): remove gated model from suggested list

claude_opus_4_8 is behind a feature flag and not open to users yet.

* docs(ai-gateway): address review feedback on tone, accuracy, and example length

Tighten the backend-function rationale, merge the redundant Models
intro sentence into the model-options pointer, correct the
Authentication Modes section (no permission difference between
modes, just which token is returned), note that per-user usage
limits are left to the caller to build, and shorten both example
tab titles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants