← All guides

Add SMS to a Base44 App: OTP Codes from a Backend Function

To add SMS to a Base44 app, save your Telmian API key as an app secret, then ask the AI chat for two backend functions: sendOtp calls POST /v1/verify and verifyOtp calls POST /v1/verify/check. Your page calls them with base44.functions.invoke. The key stays on the server. Test free in the sandbox, then pay €0.05 per SMS segment plus VAT.

Where each piece goes in Base44
PieceWhere in Base44Note
Telmian API keyApp secret (Set secrets card or Secrets page)Read it with secrets.get inside the handler
Code that calls TelmianBackend function (Deno, TypeScript)Never in frontend code
Call from the pagebase44.functions.invoke("sendOtp", {...})Result is on response.data
Phone loginNot built inBuild it with sendOtp and verifyOtp
Telmian MCPCustom MCP connection, Builder plan or higherBuild chat only, not the live app
  1. Get a sandbox key

    Create a free account at https://app.telmian.com and get a sandbox key. It starts with sk_test_, needs no card, and only simulates SMS. If you use a terminal, npx telmian@1 init writes one to a .env file.

  2. Save the key as a Base44 secret

    When the AI chat shows a "Set secrets" card, paste the key as TELMIAN_API_KEY and click Submit Secrets. You can change it later on the app's Secrets page, or with the Base44 CLI.

    base44 secrets set TELMIAN_API_KEY=sk_test_...
  3. Ask the AI chat for a sendOtp backend function

    Ask for a backend function, not frontend code, and give the exact Telmian endpoint so the AI does not invent one. Read the secret inside the handler, not at the top of the file, or it comes back undefined. Function URLs are public, so check that the user is signed in before sending.

    import { createClientFromRequest } from "npm:@base44/sdk";
    import { secrets } from "base44:runtime";
    
    export default async function (req: Request): Promise<Response> {
      const base44 = createClientFromRequest(req);
      const user = await base44.auth.me();
      if (!user) return Response.json({ error: "Sign in first" }, { status: 401 });
      const { phone, signupAttemptId } = await req.json();
      const TELMIAN_API_KEY = await secrets.get("TELMIAN_API_KEY");
      const res = await fetch('https://app.telmian.com/v1/verify', { method: 'POST', headers: { Authorization: `Bearer ${TELMIAN_API_KEY}`, 'Content-Type': 'application/json', 'Idempotency-Key': signupAttemptId }, body: JSON.stringify({ phone }) });
      return Response.json({ sent: res.ok }, { status: res.ok ? 200 : 502 });
    }
  4. Add a verifyOtp backend function

    A second function checks the code the user typed. Telmian answers with valid true or false, so you never store codes yourself.

    import { createClientFromRequest } from "npm:@base44/sdk";
    import { secrets } from "base44:runtime";
    
    export default async function (req: Request): Promise<Response> {
      const base44 = createClientFromRequest(req);
      const user = await base44.auth.me();
      if (!user) return Response.json({ error: "Sign in first" }, { status: 401 });
      const { phone, code } = await req.json();
      const TELMIAN_API_KEY = await secrets.get("TELMIAN_API_KEY");
      const check = await fetch('https://app.telmian.com/v1/verify/check', { method: 'POST', headers: { Authorization: `Bearer ${TELMIAN_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ phone, code }) }); const { valid } = await check.json();
      return Response.json({ valid });
    }
  5. Call the functions from your page

    Use base44.functions.invoke. It returns an axios response, so the result is on .data. If a send fails because of a network error, retry with the same attemptId so the user does not get two codes.

    const attemptId = crypto.randomUUID();
    await base44.functions.invoke("sendOtp", { phone, signupAttemptId: attemptId });
    
    // after the user types the code
    const check = await base44.functions.invoke("verifyOtp", { phone, code });
    if (check.data.valid) {
      // phone verified
    }
  6. Test with the sandbox numbers

    With the sk_test_ key, +393000000001 always receives code 000000 and +393000000002 always fails. Try both, so you see the success screen and the error screen.

  7. Go live

    Top up by card from €5, set an approved business name in the panel, and create an sk_live_ key. Replace the TELMIAN_API_KEY secret, then republish the app, because a published version may keep the old value until you do.

Questions

Can I put the Telmian API key in my Base44 frontend code?

No. Anyone could read it in the browser and send SMS on your balance. Keep it as an app secret and call Telmian only from a backend function.

Does Base44 have phone number login built in?

No. Base44 login uses email and password, Google, Microsoft, Facebook, Apple or SSO. Its SMS for multi-factor login is sent by Base44 itself on the Builder plan or higher, and Telmian does not replace it. For phone verification inside your app, build sendOtp and verifyOtp as shown above. The Telmian Supabase hook does not apply, since Base44 has its own auth and database.

Why does my backend function get undefined for the API key?

You probably call secrets.get at the top of the file. Call it inside the handler. If you changed the key, republish the app, because a published version may keep the old value.

Which Base44 plan do I need?

Base44's billing page lists backend functions on the Free plan, so the AI chat can create them. Editing code yourself in the editor needs Starter or higher. Custom MCP connections need Builder or higher.

Can I connect the Telmian MCP server to Base44?

Optionally, if you are on Builder or higher, you can try adding https://app.telmian.com/mcp as a custom MCP connection so the build chat can use Telmian tools, such as set_sender_profile to set your business name. We have not tested Telmian's sign-in inside Base44. Base44 MCP connections work only in the build chat, so your live app still needs the backend functions and the secret.

Updated