Updated on 2026-11-06 GMT+08:00

Running a Job

Function

This API is used to run a Ray job. This is an asynchronous API that returns a job ID after a request is submitted successfully. The job does not complete immediately. You need to call the Viewing Ray Job Details API to check the job status. When the job status is SUCCEEDED, the job has been run successfully.

Calling Method

For details, see Calling APIs.

URI

POST /v2/workspaces/{workspace_id}/ray-jobs

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

workspace_id

Yes

String

Definition: Workspace ID. For details about how to obtain the workspace ID, see Obtaining a Workspace ID.

Constraints: N/A

Range: 1 to 36 characters. Only letters, digits, and hyphens (-) are allowed.

Default Value: N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition: User token. It is obtained by calling the Obtaining an IAM User Token API.

Constraints: N/A

Range: Up to 65,534 characters.

Default Value: N/A

X-Client-Token

No

String

Definition: Job transaction ID, which is used to prevent duplicate submissions.

Constraints: N/A

Range: Up to 65,534 characters.

Default Value: N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Definition: Job name.

Constraints: N/A

Range: 1 to 47 characters. Only letters, digits, and hyphens (-) are allowed.

Default Value: N/A

endpoint_name

Yes

String

Definition: Endpoint name.

Constraints: N/A

Range: 1 to 63 characters. Only lowercase letters, digits, and hyphens (-) are allowed. The value must start with a lowercase letter and end with a lowercase letter or digit.

Default Value: N/A

config

Yes

RayJobConfig object

Definition: Ray job configuration. The key is the configuration item name, and the value is the configuration item value.

Constraints: N/A

description

No

String

Definition: Description.

Constraints: N/A

Range: 0 to 1,024 characters. Only letters, digits, underscores (_), hyphens (-), periods (.), and spaces are allowed.

Default Value: N/A

Table 4 RayJobConfig

Parameter

Mandatory

Type

Description

entrypoint

Yes

String

Definition: Main script for running a job. When a job is run, the .zip file of the job script is automatically decompressed. If the first-level directory contains only one folder after decompression, that folder is automatically stripped. Therefore, you only need to specify the script file name, without including the parent directory.

Constraints: N/A

Range: 1 to 102,400 characters.

Default Value: N/A

runtime_env

No

RuntimeEnv object

Definition: Runtime environment configuration for a job.

Constraints: N/A

Default Value: N/A

image

No

V2ImageBriefInfo object

Definition: Image information.

Constraints: Configured only when a job is submitted to a RayJob endpoint.

resource_config

No

RayResourceConfig object

Definition: Ray node resource configuration.

Constraints: Configured only when a job is submitted to a RayJob endpoint.

rayjob_strategy

No

RayJobStrategy object

Definition: Ray job submission policy.

Constraints: N/A

metadata

No

Map<String,String>

Definition: User-defined job metadata (key-value pairs).

Constraints: 0 to 255 key-value pairs. Both key and value must be non-empty and no longer than 255 characters.

Table 5 RuntimeEnv

Parameter

Mandatory

Type

Description

working_dir

No

String

Definition: Working directory where the code will run.

Constraints: Must be a remote URI, for example, an OBS path.

Range: 1 to 2048.

Default Value: N/A

pip

No

Array of strings

Definition: A list of pip packages to install.

Constraints: 0 to 1023.

env_vars

No

Map<String,String>

Definition: Environment variables to set. The key is the environment variable name, and the value is the environment variable value. Both are of the String type.

Constraints: N/A

config

No

Map<String,Object>

Definition: Runtime environment configuration. The key is the configuration item name, and the value is the configuration item value.

Constraints: N/A

Table 6 V2ImageBriefInfo

Parameter

Mandatory

Type

Description

image_id

Yes

String

Definition: Image ID. For details about how to obtain it, see Listing Images.

Constraints: N/A

Range: 32 to 36 characters. Only letters, digits, and hyphens (-) are allowed.

Default Value: N/A

image_version_id

Yes

String

Definition: Image version ID. For details about how to obtain it, see Querying Details of an Image.

Constraints: N/A

Range: 32 to 36 characters. Only letters, digits, and hyphens (-) are allowed.

Default Value: N/A

Table 7 RayResourceConfig

Parameter

Mandatory

Type

Description

head_resource_spec

Yes

RayHeadResourceSpec object

Definition: Head resource configuration.

Constraints: Configured only when a job is submitted to a RayJob endpoint.

worker_resource_spec

Yes

Array of RayWorkerResourceSpec objects

Definition: Worker resource configuration.

Constraints: Configured only when a job is submitted to a RayJob endpoint.

Table 8 RayHeadResourceSpec

Parameter

Mandatory

Type

Description

cpu

Yes

Integer

Definition: Number of CPU cores, in millicores.

Constraints: N/A

Range: The minimum value is 1000.

Default Value: N/A

memory

Yes

Integer

Definition: Memory size for a single head node, in MB.

Constraints: N/A

Range: The minimum value is 1024.

Default Value: N/A

gpu

No

Double

Definition: Number of GPUs on a node.

Constraints: Values less than 1 or with decimal fractions (e.g., 0.5, 1.5) are not supported.

Range: Must be greater than or equal to 1.0 and must be an integer value (e.g., 1.0, 2.0, 3.0, ...).

Default Value: N/A

npu

No

Double

Definition: Number of NPUs on a node.

Constraints: Values less than 1 or with decimal fractions (e.g., 0.5, 1.5) are not supported.

Range: Must be greater than or equal to 1.0 and must be an integer value (e.g., 1.0, 2.0, 3.0, ...).

Default Value: N/A

Table 9 RayWorkerResourceSpec

Parameter

Mandatory

Type

Description

cpu

Yes

Integer

Definition: Number of CPU cores, in millicores.

Constraints: N/A

Range: The minimum value is 1000.

Default Value: N/A

memory

Yes

Integer

Definition: Memory size, in MB.

Constraints: N/A

Range: The minimum value is 1024.

Default Value: N/A

gpu

No

Double

Definition: Number of GPUs on a node.

Constraints: Values less than 1 or with decimal fractions (e.g., 0.5, 1.5) are not supported.

Range: Must be greater than or equal to 1.0 and must be an integer value (e.g., 1.0, 2.0, 3.0, ...).

Default Value: N/A

npu

No

Double

Definition: Number of NPUs on a node.

Constraints: Values less than 1 or with decimal fractions (e.g., 0.5, 1.5) are not supported.

Range: Must be greater than or equal to 1.0 and must be an integer value (e.g., 1.0, 2.0, 3.0, ...).

Default Value: N/A

worker_replicas

No

Integer

Definition: Number of worker replicas.

Constraints: N/A

Range: 1 to 64

Default Value: N/A

enable_autoscaling

Yes

Boolean

Definition: Specifies whether to enable auto scaling for worker nodes.

Constraints: N/A

Range

  • true: Enable auto scaling. If this value is used, worker_min_replicas and worker_max_replicas must be set.

  • false: Disable auto scaling. If this value is used, worker_replicas must be set.

Default Value: false

worker_min_replicas

No

Integer

Definition: Minimum number of worker replicas.

Constraints: N/A

Range: 0 to 64

Default Value: N/A

worker_max_replicas

No

Integer

Definition: Maximum number of worker replicas.

Constraints: N/A

Range: 1 to 64

Default Value: N/A

Table 10 RayJobStrategy

Parameter

Mandatory

Type

Description

queued_timeout

No

Integer

Definition: Job submission timeout. If the job has not started running after this time, the job fails. The unit is minute.

Constraints: N/A

Range: 10 to 1440.

Default Value: 180 (3 hours)

running_timeout

No

Integer

Definition: Job runtime timeout. If the job has not finished running after this time, the job will be canceled and marked as failed. The unit is minute.

Constraints: N/A

Range: -1 to 10080 (-1 indicates no timeout is configured).

Default Value: -1

Response Parameters

Status code: 202

Table 11 Response body parameters

Parameter

Type

Description

job_id

String

Definition: Job ID. It can be obtained by calling the Listing Ray Jobs API.

Range: 1 to 36 characters. Only letters, digits, and hyphens (-) are allowed.

Status code: 400

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Definition: Error code.

Range: 8 to 36 characters.

error_msg

String

Definition: Error description.

Range: 2 to 512 characters.

solution_msg

String

Definition: Solution description.

Range: 0 to 4,096 characters.

Status code: 401

Table 13 Response body parameters

Parameter

Type

Description

error_code

String

Definition: Error code.

Range: 8 to 36 characters.

error_msg

String

Definition: Error description.

Range: 2 to 512 characters.

solution_msg

String

Definition: Solution description.

Range: 0 to 4,096 characters.

Status code: 403

Table 14 Response body parameters

Parameter

Type

Description

error_code

String

Definition: Error code.

Range: 8 to 36 characters.

error_msg

String

Definition: Error description.

Range: 2 to 512 characters.

solution_msg

String

Definition: Solution description.

Range: 0 to 4,096 characters.

Status code: 404

Table 15 Response body parameters

Parameter

Type

Description

error_code

String

Definition: Error code.

Range: 8 to 36 characters.

error_msg

String

Definition: Error description.

Range: 2 to 512 characters.

solution_msg

String

Definition: Solution description.

Range: 0 to 4,096 characters.

Status code: 408

Table 16 Response body parameters

Parameter

Type

Description

error_code

String

Definition: Error code.

Range: 8 to 36 characters.

error_msg

String

Definition: Error description.

Range: 2 to 512 characters.

solution_msg

String

Definition: Solution description.

Range: 0 to 4,096 characters.

Status code: 500

Table 17 Response body parameters

Parameter

Type

Description

error_code

String

Definition: Error code.

Range: 8 to 36 characters.

error_msg

String

Definition: Error description.

Range: 2 to 512 characters.

solution_msg

String

Definition: Solution description.

Range: 0 to 4,096 characters.

Example Requests

Run a Ray job.

POST /v2/workspaces/{workspace_id}/ray-jobs

{
  "name" : "rayjob0615-4",
  "description" : "run Ray Job",
  "endpoint_name" : "ray-test",
  "config" : {
    "entrypoint" : "python3 create_csv.py",
    "runtime_env" : {
      "working_dir" : "obs://ray-shared-csc/ray-zy/create_csv.zip",
      "pip" : [ "numpy==1.16.1" ],
      "env_vars" : {
        "APP_PORT" : "8848",
        "NODE_ENV" : "production"
      }
    },
    "image" : {
      "id" : "dd877a59-5cbd-44c5-b8a7-dc464cca****",
      "image_version" : "01ae8ee6-af8a-48a8-895b-8d4a70bf****"
    }
  }
}

Example Responses

Status code: 202

{
  "job_id" : "ac8111bf-3601-4905-8ddd-b41d3e636a4e"
}

Status code: 400

{
  "error_code" : "common.01000001",
  "error_msg" : "failed to read http request, please check your input, code: 400, reason: Type mismatch., cause: TypeMismatchException",
  "solution_msg" : "Check whether the request parameters comply with the API definition and try again."
}

Status code: 401

{
  "error_code" : "APIG.1002",
  "error_msg" : "Incorrect token or token resolution failed",
  "solution_msg" : "Please check if auth token is included in the request header."
}

Status code: 403

{
  "error_code" : "APIG.1003",
  "error_msg" : "X-Auth-Token is invalid in the request",
  "solution_msg" : "Check whether the token in the request is valid and try again."
}

Status code: 404

{
  "error_code" : "common.01000001",
  "error_msg" : "response status exception, code: 404",
  "solution_msg" : "Please try to use correct info."
}

Status code: 408

{
  "error_code" : "common.00000408",
  "error_msg" : "timeout exception occurred",
  "solution_msg" : "The backend request timed out — check service health and network connectivity, then retry."
}

Status code: 500

{
  "error_code" : "common.00000500",
  "error_msg" : "internal error",
  "solution_msg" : "Contact operations for analysis."
}

Status Codes

Status Code

Description

202

Request submitted.

400

Invalid request.

401

Unauthorized.

403

Request denied.

404

The requested resource could not be found.

408

Request timeout.

500

Internal server error.