Help centerAPI Gateway & AuthMesh
AuthMesh
Call paid APIs (with a secret key) straight from the browser without exposing the key, with allowed paths, user login and per-minute limits.
Apps built with no-code builders and SPAs often need to call a paid API (maps, AI, payments) straight from the browser, and the secret key ends up visible to anyone. With AuthMesh, the secret stays with Tenanci: the browser calls an address on the customer's own domain and Tenanci adds the credential on the way, only for the paths, methods and users you allowed.
How it works
Each service gets an address on every domain of the project:
https://<customer domain>/__tenanci/mesh/<identifier>/<path> → <API base URL>/<path>On every call, Tenanci checks, in this order: whether the method and path are allowed, whether the call comes from the site itself (or an allowed origin), the body size, the per-minute limit and who is calling. If everything passes, it strips the visitor's cookies and login headers, adds the service credential and forwards the call. The browser never sees the secret, and the target API can't set cookies on the domain.
Create a service
- Open the project and go to the Gateway & AuthMesh tab.
- In the AuthMesh card, click New service.
- Fill in Name and URL identifier (lowercase letters, numbers and hyphens, e.g.
maps,openai). - Under API base URL, enter the
https://address of the target API (e.g.https://api.example.com/v1). - Under Credential, choose how the API expects the key:
- Bearer token: sent as
Authorization: Bearer <secret>; - Header: sent in a header with the name you enter under Header/parameter name;
- Basic (user:password): the secret in
user:passwordformat; - URL parameter: sent as
?<name>=<secret>.
- Bearer token: sent as
- Type the Secret.
- Under Allowed methods, check only the ones the app uses.
- Under Allowed paths (one per line), list the permitted paths, such as
/v1/geocodeor/v1/places/*. Nothing is allowed by default. - Pick Who can call (see below), adjust Limit per minute (per user/IP) and Max body (KB) and click Save.
- The service is created switched off. Flip the toggle next to its name to activate it. If something is missing, the dashboard shows To activate: with the list of things to fix.
Under each service, the dashboard shows a ready-to-use front-end snippet with one of the project's domains.
Who can call
| Option | How Tenanci checks | What you provide |
|---|---|---|
| Logged-in user (your app's JWT) | the browser sends Authorization: Bearer <user token>; Tenanci validates the token signature |
your login provider's JWKS URL; optionally Issuer (iss) and Audience (aud) |
| Logged-in user (session checked on your backend) | Tenanci forwards the call's cookies and Authorization to your URL; a 2xx answer = valid session (the result is cached for up to 1 minute) |
Session introspection URL |
| Any site visitor | nobody needs to be logged in | checking the acknowledgement that any visitor can use the credential within the allowed paths |
With a logged-in user, the per-minute limit applies per user and per IP; with any visitor, per IP.
Allowed origins
By default, only the domain itself can call the service. If another site needs to call it (for example, the app at
https://app.customer.com calling the service on customer.com), add that address under Allowed origins (CORS,
one per line).
Using it in the front end
const token = await auth.getToken(); // the JWT of the user logged in to your app
const r = await fetch("/__tenanci/mesh/maps/v1/geocode?q=Main%20St%2C%20Austin", {
headers: { Authorization: `Bearer ${token}` },
});
const data = await r.json();Responses from Tenanci itself when a call doesn't get through:
| HTTP | When |
|---|---|
| 401 | not logged in, invalid token or invalid session |
| 403 | path not allowed or origin not permitted |
| 405 | method not allowed |
| 413 | body larger than Max body (KB) |
| 429 | over the per-minute limit (with Retry-After) |
Through the API
Services belong to the project (projects:write scope): GET and
POST /projects/:p/authmesh,
PATCH and DELETE /projects/:p/authmesh/:id.
To activate, send "enabled": true in the PATCH; if the setup is incomplete, the response is 422 with the list
of what's missing.
curl -X POST https://api.tenanci.com/v2/projects/prj_8f3k2m/authmesh \
-H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"name": "Maps", "slug": "maps", "upstreamBaseUrl": "https://api.example.com",
"credential": { "kind": "bearer", "secret": "sk_live_..." },
"allowedMethods": ["GET"], "allowedPaths": ["/v1/geocode", "/v1/routes/*"],
"callerAuth": "jwt", "jwksUrl": "https://login.example.com/.well-known/jwks.json",
"rateLimitPerMin": 30
}'
# → { "id": "...", "slug": "maps", "enabled": false, "hasCredential": true, ... }
curl -X PATCH https://api.tenanci.com/v2/projects/prj_8f3k2m/authmesh/<id> \
-H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" -H "Content-Type: application/json" \
-d '{"enabled":true}'const svc = await tenanci.request<{ id: string }>("POST", "/projects/prj_8f3k2m/authmesh", {
name: "Maps",
slug: "maps",
upstreamBaseUrl: "https://api.example.com",
credential: { kind: "bearer", secret: process.env.MAPS_KEY },
allowedMethods: ["GET"],
allowedPaths: ["/v1/geocode", "/v1/routes/*"],
callerAuth: "jwt",
jwksUrl: "https://login.example.com/.well-known/jwks.json",
});
await tenanci.request("PATCH", `/projects/prj_8f3k2m/authmesh/${svc.id}`, { enabled: true });
