文档

​
​

Development

User Acquisition

Monetization

工业

Cloud Code Client API

v1

受支持
​

Cloud Code Client API

v1

受支持
​

此页面不支持所选语言。
Unity Services Web APIs
​
​
Cloud Code
  • Overview
mdx:openapi:endpoints
  • Cloud Code

Cloud Code

Overview

This is the API specification for the Unity Cloud Code service that enables game developers to run custom server-side code for their games.

Limits

The combined size of the
POST
request body cannot exceed 1 MB.
The combined size of the response body cannot exceed 2 MiB.
The API has rate limiting in place. Request are limited on a per-player basis to 600 requests per minute which would allow for a sustained 10 requests per second.
The API responds with a
429
HTTP status code if the rate limit is exceeded.
It will also respond with a
Retry-After
header to be used in conjunction with a client's retry logic. The value is the number of seconds until a request for the given player will be accepted.

Modules

You can deploy a Cloud Code module with the UGS CLI by using the deploy command, or by using the Cloud Code admin APIs. Cloud Code modules are C# projects built either with .NET Core or .NET Framework.
A Cloud Code module can have one or more Cloud Code functions, which are defined with the attribute
CloudCodeFunction
. For example, the following code represents a Cloud Code module named
HelloWorld
with a function named
SayHello
.
SayHello
accepts a single string parameter called
name
.
public class HelloWorld{ [CloudCodeFunction("SayHello")] public string SayHello(string name) { return $"Hello, {name}!"; }}

Scripts

You can create a Cloud Code script in the UGS dashboard, or by using the Cloud Code admin APIs.

Useful Links

  • Cloud Code
Download OpenAPI specification:

Run script


Run a Cloud Code script for a project.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
ServiceAccount
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: bearer

Path parameters for "{title}"

projectId

string
必填
example: 8bdacc33-6eef-4577-beb0-633c86259f5b
ID of the project.

scriptId

必填
Name of the script.

Request body for "{title}"

Media Type:
application/json

params

object
必填
Object containing key-value pairs that map on to the parameter definitions for the script. Parameters are required according to the definition.

HTTP response status codes for "{title}":

Code samples for "{title}":

Request example

curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "params": {}}' \ "https://cloud-code.services.api.unity.com/v1/projects/{projectId}/scripts/{scriptId}"

Response example

{ "output": { "playerInfo": { "playerID": "TestUser", "userName": "TestUserName", "displayName": "Name", "email": "test@test.com", "country": null, "deviceType": null, "platform": "IOS", "dateCreated": "string" } }}

Run module function


Run a Cloud Code function from a module for a project.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
ServiceAccount
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: bearer

Path parameters for "{title}"

projectId

string
必填
example: 8bdacc33-6eef-4577-beb0-633c86259f5b
ID of the project.

moduleId

必填
Name of the Cloud Code module.

functionId

必填
Name of the function to invoke from the given module.

Request body for "{title}"

Media Type:
application/json

params

object
必填
Object containing key-value pairs that map on to the parameter definitions for the given function of a module. Parameters are required according to the arguments defined in the function signature.

HTTP response status codes for "{title}":

Code samples for "{title}":

Request example

curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "params": {}}' \ "https://cloud-code.services.api.unity.com/v1/projects/{projectId}/modules/{moduleId}/{functionId}"

Response example

{ "output": true}

Create a player subscription token


Create a subscription token for player messages.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
ServiceAccount
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: bearer

Path parameters for "{title}"

projectId

string
必填
example: 8bdacc33-6eef-4577-beb0-633c86259f5b
ID of the project.

HTTP response status codes for "{title}":

Code samples for "{title}":

Request example

curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Authorization: Bearer <YOUR_TOKEN>" \ "https://cloud-code.services.api.unity.com/v1/projects/{projectId}/subscriptions/tokens/player"

Response example

{ "channel": "$cloud-code!!!player-YL9Ia3mKqq0s620EsWhcc3PW2U3D!!!fc1099a0-a0af-44fe-9c0c-b4b068a090cc!!!b90c4336-189e-494f-82e6-ca4c774cbaec", "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImNsb3VkLWNvZGU6YWY2ZjlmMzItMGEwMy00MjM5LWI4MTQtOWZhZGZmYmU1NjA5IiwidHlwIjoiSldUIn0.eyJlbnZpcm9ubWVudE..."}

Create a project subscription token


Create a subscription token for project messages.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
ServiceAccount
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: bearer

Path parameters for "{title}"

projectId

string
必填
example: 8bdacc33-6eef-4577-beb0-633c86259f5b
ID of the project.

HTTP response status codes for "{title}":

Code samples for "{title}":

Request example

curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Authorization: Bearer <YOUR_TOKEN>" \ "https://cloud-code.services.api.unity.com/v1/projects/{projectId}/subscriptions/tokens/project"

Response example

{ "channel": "$cloud-code!!!project!!!fc1099a0-a0af-44fe-9c0c-b4b068a090cc!!!b90c4336-189e-494f-82e6-ca4c774cbaec", "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImNsb3VkLWNvZGU6YWY2ZjlmMzItMGEwMy00MjM5LWI4MTQtOWZhZGZmYmU1NjA5IiwidHlwIjoiSldUIn0.eyJlbnZpcm9ubWVudE..."}

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。