Back to blog
Product UpdatesDec 2, 2026

Func backend updates: Stripe subscriptions, OpenAI and speech, remote MCP, run logs

What Funcs gained from September to November: ctx.payment.stripe for payments and subscriptions, ctx.ai for chat and image generation, ctx.tts for speech, and ctx.mcp for calling remote MCP tools with OAuth. Plus run logs for live Funcs in the editor, grouped stats, cursor paging and range filters on JSON tables, members-only Funcs, and timeouts declared in source.

Creght

Product Updates

Stripe subscriptions, OpenAI, MCP

Our August post, Creght's backend, listed two limits: JSON tables had no aggregation, and the payment docs only covered Alipay. Neither holds anymore. Between September and November, Funcs picked up a set of new capabilities. This post goes through them by task, with where to find each one and its docs.

Card payments and subscriptions: Stripe

In the editor, open Backend → Integrations and click Stripe. Fill in your Secret key, whether this is live mode (real money), and the pages to return to after payment and after cancel. Saving makes a real call to Stripe, so a mistyped key, a test key with live mode ticked, or a pasted Publishable key fails right there instead of when someone tries to pay.

Then use ctx.payment.stripe in a Func:

  • checkoutSession creates a Stripe Checkout page for a one-time payment and returns its URL; when the buyer comes back, retrieveSession confirms the payment.

  • subscriptionSession starts a subscription. The price can be a priceId you created in Stripe, or an amount and interval written inline. Trial days and promotion codes are supported.

  • billingPortalSession returns a Stripe-hosted billing page where customers change their card, see invoices and cancel. You don't build those screens.

  • verifyWebhook checks the signature on events from Stripe. Subscription events also carry a normalized subscription: which of your subscriptions it belongs to, whether it is active (trials count as active), and when the current period ends.

const session = ctx.payment.stripe.subscriptionSession({
  clientReferenceId: subNo,   // your own subscription number, saved to your table first
  priceId: 'price_xxx',
  customerEmail: user.email,
  trialDays: 14,
})
return { payUrl: session.url }

A few mistakes that would otherwise fail silently are handled for you:

  • Amounts must be integers in the smallest currency unit (500 is $5.00). Passing '9.90' throws instead of quietly charging 9 cents.

  • Renewal invoices have no Checkout Session attached. The platform writes your subscription number onto the subscription itself; without that, renewals from the second period on can't be matched to any user.

  • Stripe's test and live events can point at the same URL. Every event is checked against your live-mode setting, so test events never reach a live site's fulfillment code.

The Secret key and webhook signing secret stay on the server and never appear in Func code. The integration card shows the webhook URL to enter in Stripe, in the form https://your-domain.com/func/stripe.webhook. It has to be a published production domain; preview domains don't receive events.

Full walkthrough: Accept Stripe payments with the integration.

Models, image generation and text-to-speech

Integrations now include OpenAI and Azure speech, available in Funcs as ctx.ai.openai and ctx.tts.azure:

  • ctx.ai.openai.chat: one chat call, for translating, extracting or classifying. With json: true, the platform strips the code fences models like to add and parses the result into data. With tools, the tool the model wants to call and its arguments, already parsed into an object, come back in toolCalls. Point the base URL at any OpenAI-compatible gateway and your site code stays the same.

  • ctx.ai.openai.image: image generation. With upload: true the image goes straight into your project's storage and you get a permanent URL. Image URLs returned by OpenAI expire after about an hour; store one in your database and the images slowly turn into 404s after launch.

  • ctx.tts.azure.speak: text to speech, with voice, rate, pitch and speaking style. With upload: true it returns a URL you can put straight into <audio>. It only accepts plain text, which the platform escapes before building the SSML, so tags hidden in user input can't change the voice.

const r = ctx.ai.openai.chat({
  messages: [{ role: 'user', content: `Extract the name and city as JSON: ${input.text}` }],
  json: true,
})
return { name: r.data.name, city: r.data.city }

Both integrations make a real request upstream when you save, so a wrong key fails immediately (for Azure, the region is checked too). Keys are not given to Func code by default. For endpoints the platform doesn't wrap, use ctx.ai.openai.call('/embeddings', …), which also keeps the key out of your code. One project can hold several configurations told apart by a channel tag; pick one with ctx.ai.openai.via('cheap').

These are single calls: the platform doesn't run multi-turn agent loops for you, and there is no streaming output.

Docs: Call OpenAI models with the integration | Text-to-speech with the integration.

Calling other services' MCP tools from a Func

Integrations now include MCP. Give the server a name and its Streamable HTTP URL (usually ending in /mcp), and pick OAuth, Token or no authentication. For servers that need a sign-in, such as Linear, Notion or Sentry, click Authorize on the card and approve in the popup. The card then shows the connection status and every tool the server offers.

const issue = await ctx.mcp('linear', 'create_issue', { title: input.title, team: 'ENG' })

With OAuth, you authorize your own account once in the editor and every call uses it, which suits connecting your own tools to your site. Tokens are encrypted and refreshed by the platform before they expire; Func code never sees them.

Limits: only Streamable HTTP is supported, not the older HTTP + SSE transport or local stdio servers. Each call opens a new connection, so it isn't suited to dozens of calls in one request. Docs: Connect MCP servers (with OAuth).

Seeing what your live Funcs logged

When a visitor triggered a Func on their own phone, its console.log output used to be out of your reach. Now click Run logs in the header of the list under Backend → Funcs to see console output from real runs, labeled as coming from the live site, preview or the editor. You can filter by Func or show errors only.

Only runs that logged something or failed are recorded. Very long output is cut off at the end, and records are kept for 7 days.

JSON tables: grouped stats, full scans, range conditions

Counting sign-ups per day used to mean reading every row and adding them up yourself. ctx.db now has:

  • ctx.db.aggregate for grouped stats: group by a field, or by created_at truncated to day, week, month or year. Metrics are count, sum, avg, min, max, first and last.

  • cursor on ctx.db.query for paging by id (with order_by: 'id asc'). Read a whole table without offsets, with no duplicates even while rows are being written.

  • Range conditions in filter: gt, gte, lt, lte and between, for example orders within a date range.

  • Automatic timestamps: new records get created_at, and updated_at is refreshed on every update.

const { list } = ctx.db.aggregate('signups', {
  group_by: [{ field: 'created_at', trunc: 'day', as: 'day' }],
  metrics: [{ op: 'count', as: 'n' }],
  timezone: 'America/New_York',
})
// each row in list is { day, n }

JSON tables still have no joins or transactions.

Funcs only for you and your team

For an admin panel or an internal tool, Funcs shouldn't be open to every visitor. Under Backend → Auth → Settings & OAuth there is a new switch to let only project members call Funcs. With it on, any call from someone not signed in as a project member gets a 401. Members sign in on the site at /auth/member/login with their own Creght account.

In a Func, ctx.member.current() tells you which member is calling, and ctx.member.require('owner') lets only the project owner through. Functions that must stay public, such as payment callbacks, declare export const config = { public: true } in their source and keep working with the switch on.

Smaller changes

  • Timeouts are declared in the Func source: export const config = { timeoutMs: 120000 }. Before, the timeout could only come from the page making the call, and visitors could change it. The declaration ships with your site version and visitors can't touch it. A timeout passed by the caller still works; the declaration takes precedence. Docs: Timeouts and streaming responses.

  • ctx.request.url and ctx.request.query give you the full request URL and query parameters. Tools like Zapier or Elementor often let you enter only a URL, with no custom headers, so a secret has to go in ?k=…. Funcs can now read it directly.

  • Global URL and URLSearchParams: new URL() used to throw a ReferenceError in Funcs. Parsing addresses and building query strings no longer needs hand-written regexes.

Render diagnostics