Custom Container runtimes host your HTTP server inside a container. Function Compute converts every function invocation into an HTTP request, forwards it to your server, and converts the HTTP response back into a function invocation response.
How it works
Function Compute supports two invocation methods:
HTTP calls (recommended): Invoke a function via an HTTP trigger or a custom domain name. Function Compute passes HTTP requests and responses between the client and your HTTP server with minimal transformation.
API calls: Invoke a function by calling the
InvokeFunctionoperation — for example, through an SDK or an event source. Function Compute converts theInvokeFunctionrequest into an HTTP POST request and forwards it to the fixed path/invokeon your HTTP server.
The request and response format your HTTP server receives depends on the invocation method.
Limitations
HTTP trigger
Only one HTTP trigger can be created for an HTTP function in each version or alias. For more information, see Manage versions and Manage aliases.
Request limits
Request headers cannot include custom fields starting with x-fc-, or the following reserved fields:
connectionkeep-alive
The system returns status code 400 and error code InvalidArgument if a request exceeds any of the following limits:
| Resource | Limit |
|---|---|
| Headers size | 8 KB (total of all keys and values) |
| Path size | 4 KB (including all query parameters) |
| Body size — synchronous invocation | 32 MB |
| Body size — asynchronous invocation | 128 KB |
Response limits
Response headers cannot include custom fields starting with x-fc-, or the following reserved fields:
connectioncontent-lengthdatekeep-aliveservercontent-disposition:attachment
When using the defaultaliyuncs.comdomain, Function Compute forcibly addscontent-disposition: attachmentto all response headers, causing browsers to download responses as attachments instead of rendering them. To remove this restriction, configure a custom domain name. For more information, see Configure a custom domain name.
The system returns status code 502 and error code BadResponse if a response exceeds the following limit:
| Resource | Limit |
|---|---|
| Headers size | 8 KB (total of all keys and values) |
Path routing
Bind a custom domain name to map different HTTP paths to functions. For more information, see Configure a custom domain name.
HTTP calls (recommended)
Function Compute passes HTTP requests from clients to your HTTP server and passes HTTP responses back to clients in passthrough mode. Some system-reserved fields are not passed. For details, see Limitations.
Request headers
When invoking a function via an HTTP trigger or a custom domain name, use the following request headers to control Function Compute behavior:
| Parameter | Type | Required | Example | Description |
|---|---|---|---|---|
X-Fc-Invocation-Type | String | No | Sync | Invocation mode. Valid values: Sync (synchronous invocation) and Async (asynchronous invocation). For more information, see Invocation methods. |
X-Fc-Log-Type | String | No | Tail | Log return method. Valid values: Tail (returns the last 4 KB of logs for the current request) and None (returns no logs; default). |
Response headers
Function Compute automatically adds the following response header to HTTP call responses:
| Parameter | Description | Example |
|---|---|---|
X-Fc-Request-Id | Request ID of the function invocation. | dab25e58-9356-4e3f-97d6-f044c4**** |
API calls
When you invoke a function using the InvokeFunction operation, Function Compute converts the request into an HTTP request and forwards it to your HTTP server at the fixed path /invoke.
Request conversion (InvokeFunction to HTTP)
| InvokeFunction field | HTTP request |
|---|---|
event parameter | Request body |
| Path | /invoke (fixed) |
| Method | POST (fixed) |
Content-Type | application/octet-stream (fixed) |
Response conversion (HTTP to InvokeFunction)
| HTTP response field | InvokeFunction response |
|---|---|
| Response body | Response body |
| Response headers | Lost during conversion |
| Status code | Lost during conversion |
Conversion examples
Request:
| InvokeFunction request | HTTP request received by the HTTP server |
|---|---|
"hello world" | POST /invoke HTTP/1.1<br>Host: 21.0.X.X<br>Content-Length: 11<br>Content-Type: application/octet-stream<br><br>hello world |
Response:
| HTTP response | InvokeFunction response |
|---|---|
HTTP/1.1 200 OK<br>Date: Mon, 10 Jul 2025 10:37:15 GMT<br>Content-Type: application/octet-stream<br>Content-Length: 11<br>Connection: keep-alive<br><br>hello world | hello world |
HTTP/1.1 400 Bad Request<br>Date: Mon, 10 Jul 2023 10:37:15 GMT<br>Content-Type: application/octet-stream<br>Content-Length: 28<br>Connection: keep-alive<br><br>{"errorMessage":"exception"} | {"errorMessage":"exception"} |
Sample code
The following Python (Flask) example implements an HTTP server that handles both HTTP calls and API calls. The server listens on port 9000 and handles GET, POST, PUT, and DELETE requests on any path.
import os
from flask import Flask, request
REQUEST_ID_HEADER = 'x-fc-request-id'
app = Flask(__name__)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE'])
def hello_world(path):
# Read the request ID injected by Function Compute
rid = request.headers.get(REQUEST_ID_HEADER)
# Read the request body
data = request.stream.read()
print("Path: " + path)
print("Data: " + str(data))
# Return a response body, status code, and a custom header
return "Hello, World!", 200, [('Function-Name', os.getenv('FC_FUNCTION_NAME'))]
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9000)Key points:
@app.route('/', defaults={'path': ''})— handles requests to the root path.@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE'])— handles requests to any other path and passes the path value tohello_worldas thepathparameter.request.headers.get(REQUEST_ID_HEADER)— reads thex-fc-request-idheader injected by Function Compute into every request.request.stream.read()— reads the request body.return "Hello, World!", 200, [('Function-Name', os.getenv('FC_FUNCTION_NAME'))]— returns a response body of"Hello, World!", status code200, and aFunction-Nameresponse header sourced from theFC_FUNCTION_NAMEenvironment variable.