Functions
Run JavaScript in the request path of an application or a firewall, invoked by a Rules Engine rule, with no server to provision.
A function is code that runs on demand, when an event such as an HTTP request arrives. You write a handler that receives the request and returns a response. The platform runs that handler for each request and stops it when the response is sent, so nothing runs between requests. This model is called serverless: there is no server to provision and no capacity to plan.
Functions holds your JavaScript code and runs it on Azion’s distributed infrastructure, in the path of a request to an application or a firewall. A rule in Rules Engine selects the function and the phase of the request that invokes it. Use Functions to build an API, rewrite request and response headers, apply logic from request metadata, or block a request before it reaches your application.
Quickstart Functions guidesFunction structure
A function exports a default object that carries one handler. In an application, the handler is named fetch:
requestis the incoming HTTP request, as aRequestobject.envcarries the environment variables and the bindings available to the function.ctxis the execution context.ctx.waitUntil(promise)extends the lifetime of the invocation.- In a firewall, the handler is named
firewalland the context addsctx.deny(), which blocks the request immediately.
Azion Runtime is built on Web standards, so what you know about the Request and Response objects applies to a function. Functions also accepts the Service Worker pattern, which registers the handler with addEventListener. For both patterns and their parameters, refer to Handlers.
Invocation path
Creating a function does not execute it. A function runs only when a rule invokes an instance of it, so two objects sit between your code and a request.
- You create a function in Functions. The function holds the code, and the same function can be instantiated in more than one application.
- You create a function instance on an application or on a firewall. The instance binds the function and carries the Args, a JSON object passed into the execution context. The code cannot be edited at instantiation, and only the Args are set there.
- You create a rule in Rules Engine and select the Run Function behavior. The rule names the instance, the execution phase, and the criteria that trigger it.
- When a request matches the criteria, the function runs on Azion’s distributed infrastructure, with no cold start.
An instance that no rule invokes never runs. For the objects, the phases, and the format of the Args, refer to How it works.
Scope and limits
- Language: you write functions in JavaScript. A function can also compile and instantiate WebAssembly modules through the WebAssembly API. A TypeScript project builds with the
Typescriptpreset of Azion CLI build, and theazion/utilspackage publishes type definitions the code imports. - Runtime: functions run on Azion Runtime, which implements the Web APIs and a set of Node.js modules. A
Responseaccepts aReadableStreamas its body, so a function streams a response to the client as it is generated instead of building the whole body first. For every body type, refer to Parameters. - Frameworks: a project built with a supported JavaScript framework becomes functions when Azion CLI builds it, through Azion Bundler, the open-source framework adapter. For the list, refer to Frameworks compatibility.
- Execution contexts: in an application, a function runs in the request phase or the response phase, and the Run Function behavior requires the Application Accelerator module. In a firewall, a function runs in the request phase and allows, denies, or drops the request.
- Platform services: a function reaches KV Store, SQL Database, and Object Storage from the runtime, and calls models through AI Inference.
- Limits: an invocation has 512 MB of memory per isolate, 2 s of CPU time, 5 min of wall-clock time including I/O wait, and 50 outbound
fetch()calls. The Args field holds 100 KB. Some values vary by plan, and the full table is in Limits. - Interfaces: you create and manage functions in Azion Console, with Azion CLI, through the Azion API, and with the Azion Terraform provider.
- Development: you write the code in the code editor in Azion Console, Preview deployment sends a simulated request and shows the response the code returns before the function serves traffic, and
azion devbuilds and runs the project locally. - Observability: a function writes log messages with
console.log, and Real-Time Events and Data Stream carry that output. - Billing: Functions is charged by compute time and by invocation, per Pricing.
Functions does not host AI models. AI Inference runs the model on Azion Runtime, and a function calls it.
AI workflows
A function is the request-time component of an AI application on Azion. It calls models through AI Inference, which serves models that follow the OpenAI API standard, so a client written against that standard works unchanged.
The pieces an AI workflow draws on sit on the same platform:
- Models: AI Inference runs the model on Azion Runtime. Functions does not host models itself.
- Retrieval: SQL Database stores vectors and supports retrieval that combines vector and full-text search, which is what a retrieval-augmented generation flow reads from.
- Agent frameworks: functions run agents built with LangGraph and LangChain.
- Agent-to-agent calls: MCP servers let agents call one another over Google’s Agent2Agent (A2A) protocol.