Cloud Function V2
New CloudBase environments will gradually use Cloud Function V2. Cloud Function V2 is billed by instance running time instead of by invocation count, and its specifications combine CPU and memory. Existing environments keep using Cloud Function V1 (the original cloud function), with no change to features or billing.
This page describes the differences between the two, and what to note when you write code, access the database, and estimate costs in Cloud Function V2.
An environment has only one type of cloud function: either Cloud Function V1 or Cloud Function V2. Existing environments are not switched automatically, and there is no upgrade button. See Existing environments and migration.
Check which version an environment uses
Option 1: In the console. The cloud function page shows whether the current environment uses "Cloud Function V1" or "Cloud Function V2".
Option 2: Call the environment info API. Call DescribeEnvInfo and check the cloud function backend type in the response:
{
"Functions": [
{ "Backend": "cbf" }
]
}
Backend value | Meaning |
|---|---|
cbf | Cloud Function V2 |
scf | Cloud Function V1 |
Differences from Cloud Function V1
| Capability | Cloud Function V1 | Cloud Function V2 | Details |
|---|---|---|---|
| Runtime | Node.js, Python, Go, PHP, Java, and more | Node.js 24 only | Runtime |
| Function types | Regular cloud functions, HTTP cloud functions | Regular cloud functions, HTTP cloud functions | — |
| Specifications | Choose by memory | Choose a specification tier, CPU:memory = 1:2, starting at 0.5 core 1 GB | Specifications |
| Maximum execution time per invocation | Regular cloud functions 900 seconds, HTTP cloud functions 7200 seconds | 900 seconds | Specifications |
| Multiple concurrent requests per instance | Configurable | Enabled by default, no configuration needed | Specifications |
| Access to the environment's database and storage | Temporary credentials issued automatically | Available after you turn on "API Key Settings" | Access database and storage |
| Total size of environment variables | 4 KB | 8 KB | Environment variables |
| Public network access | Supported | Supported, egress IP not fixed | Network |
| Private network (VPC) | Supported | Not supported yet | Network |
| Fixed egress IP | Supported | Not supported yet | Network |
| Streaming output (SSE) | Supported | Supported | — |
| WebSocket | Supported | Supported (HTTP cloud functions) | — |
| Layers | Supported | Not supported | Unsupported features |
| Provisioned concurrency | Supported | Not supported | Unsupported features |
| Timer triggers | Supported | Not supported yet | Unsupported features |
| Versions and traffic | Publish versions, split traffic by percentage | Publish versions; split traffic by percentage (up to 2 versions) or by request header | — |
| Billing | Execution time × memory (GBs) + invocations + outbound public traffic | Instance running time (CU) + outbound public traffic | Billing |
Runtime
Cloud Function V2 supports Node.js 24 only (set Runtime to Nodejs24.11 or Nodejs24.14 when you create a function). Both regular cloud functions and HTTP cloud functions can use it.
For Python, Go, Java, PHP, or other languages, use CloudRun.
Specifications
Cloud Function V2 offers CPU and memory in specification tiers. The CPU-to-memory ratio is fixed at 1:2:
| Specification | Usage per hour of running | Notes |
|---|---|---|
| 0.5 core 1 GB | 0.5 CU | Default |
| 1 core 2 GB | 1 CU | |
| 2 cores 4 GB | 2 CU |
Other limits:
| Item | Limit |
|---|---|
| Maximum execution time per invocation | 900 seconds |
| Multiple concurrent requests per instance | Enabled by default; one instance can handle multiple requests at the same time |
| Cold start time | About 1–2 seconds |
Access database and storage
Cloud Function V1 issues temporary credentials to functions automatically, so no configuration is needed in code. Cloud Function V2 does not, so complete the following three steps.
1. Install the Node SDK
Use @cloudbase/node-sdk 4.x:
npm install @cloudbase/node-sdk@latest
Version 3.x cannot access the database, storage, and other resources properly in Cloud Function V2. Upgrade to 4.x.
2. Turn on "API Key Settings" for the function
- In the console, open the function configuration and find "Environment Variables".
- Turn on "API Key Settings" and select an API key of this environment (create one if none exists).
- After you save, the function gets an environment variable named
CLOUDBASE_APIKEY.
3. Initialize the SDK
const tcb = require('@cloudbase/node-sdk')
// The SDK reads TCB_ENV and CLOUDBASE_APIKEY automatically
const app = tcb.init({ env: tcb.SYMBOL_CURRENT_ENV })
exports.main = async (event) => {
// Read and write PostgreSQL in this environment
const { data, error } = await app.rdb().from('orders').select('*').limit(1)
return { data, error }
}
Notes:
- Do not write the API key into code or commit it to a code repository. Always use it through environment variables.
- Read the environment ID from
TCB_ENVin the function.
Environment variables
- The total size of environment variables is limited to 8 KB (all names and values combined, including the API key).
- Variable names starting with
TCB_orAGS_are reserved by the system and cannot be set.
Network
| Capability | Cloud Function V2 |
|---|---|
| Public network access | Supported, egress IP not fixed |
| Private network (VPC) access | Not supported yet |
| Fixed egress IP | Not supported yet |
If your service needs to connect to resources in your own VPC, or a third-party service requires adding the egress IP to an allowlist (such as WeChat Pay or WeCom), use CloudRun for now. Upgrading your plan does not add these two capabilities to Cloud Function V2.
Unsupported features
| Feature | Cloud Function V2 | Alternative |
|---|---|---|
| Layers | Not supported | Bundle dependencies into the code package |
| Provisioned concurrency | Not supported | No configuration needed; multiple concurrent requests per instance are enabled by default |
| Timer triggers | Not supported yet | Use CloudRun for scheduled tasks |
| Private network (VPC), fixed egress IP | Not supported yet | Use CloudRun |
| Languages other than Node.js | Not supported | Use CloudRun |
| Promotional resource packs | Not applicable | — |
If you pass a configuration that Cloud Function V2 does not support (such as VPC or layers) through the API or CLI, an error is returned that names the field.
Billing
Cloud Function V1: by execution time and invocations
| Billing item | Price |
|---|---|
| Resource usage (execution time × configured memory) | 0.11108 resource points / GBs |
| Invocations | 13.3 resource points / 10,000 invocations |
| Outbound public traffic | 800 resource points / GB |
Cloud Function V2: by instance running time
| Billing item | Price |
|---|---|
| Compute usage | 220 resource points / CU |
| Outbound public traffic | 800 resource points / GB |
- 1 CU is an instance of the 1 core 2 GB specification running for 1 hour. 0.5 core 1 GB running for 1 hour is 0.5 CU, and 2 cores 4 GB running for 1 hour is 2 CU.
- Running time starts when an instance starts successfully and ends when the instance is destroyed, including the time the instance is kept after requests finish. The instance startup (cold start) is not billed.
- An instance that runs for less than 1 minute is billed as 1 minute. New requests that arrive while the instance is kept reuse it and are not billed again.
Cloud Function V2 itself is not billed by invocation count. When you call a function through the HTTP access service or the CloudBase API, these requests are still billed as gateway invocations, the same as calls to other resources. See the HTTP gateway billing adjustment announcement.
Example
Using 0.5 core 1 GB (the default specification):
| Scenario | Calculation | Resource usage |
|---|---|---|
| One invocation takes 200 ms, with no other requests for a long time before or after | The instance runs less than 1 minute, billed as 1 minute | 0.5 CU × 1/60 ≈ 0.0083 CU, about 1.83 resource points |
| One instance keeps handling requests for 1 hour | Billed as the instance running for 1 hour | 0.5 CU, 110 resource points |
Cloud Function V2 is billed by how long instances run, not by how many milliseconds your code executes. The more concentrated the requests, the more requests one instance handles and the lower the cost per request. With sporadic invocations, the 1-minute minimum makes up most of the cost.
View usage
View Cloud Function V2 resource usage in "Plan Usage" in the console. In usage details, 3600 core-seconds = 1 CU.
Existing environments and migration
- Existing environments keep using Cloud Function V1, with no change to features or billing.
- Existing environments are not switched to Cloud Function V2, and there is no upgrade button.
- An environment has only one type of cloud function.
- No tool is currently provided for migrating from Cloud Function V1 to Cloud Function V2.
FAQ
Will my environment be switched to Cloud Function V2 automatically?
No. Existing environments keep using Cloud Function V1.
What should I do when Cloud Function V2 reports "missing credentials"?
Check two things: whether @cloudbase/node-sdk is 4.x, and whether "API Key Settings" is turned on in the function configuration. See Access database and storage.
Why am I still billed after a request finishes?
After a request finishes, the instance is kept for a period so the next request can use it directly without another cold start. The kept instance still occupies resources, so the time counts toward running time.
Can Cloud Function V2 connect to my VPC or use a fixed egress IP?
Not yet. Use CloudRun for now. See Network.
How do I view function logs and monitoring?
View them in "Logs & Monitoring" in the console.