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

Using APIs to Connect to a RayJob Endpoint and Submit Jobs

If you need to integrate data processing capabilities into your service system, or to submit Ray jobs and query job status automatically, you can use APIs to connect to a RayJob endpoint and submit jobs. AI DataLake provides standard RESTful APIs that you can call programmatically.

Prerequisites

A RayJob endpoint has been created and is in the Running state. For details, see Creating a Ray Engine Endpoint.

Related APIs

Running a Job

Procedure

  1. Use an API tool, such as Postman, to call the API to connect to the RayJob endpoint and submit a job.

    For details about calling APIs, see Calling APIs.

    An example request is as follows:

    POST /v2/workspaces/{workspace_id}/ray-jobs
    {
        "name": "rayjob0615-4", 
        "endpoint_name": "ray-job-owin",
        "config": {
            "runtime_env":{
                "working_dir":"obs://ray-shared-csc/ray-job-code.zip"
            },
            "entrypoint": "python3 -m estimate_pi 1000000",
            "image": {
                "image_id": "dd877a59-5cbd-44c5-b8a7-dc464cca****",
                "image_version": "01ae8ee6-af8a-48a8-895b-8d4a70bf****"
            },
            "resource_config": {
                "head_resource_spec": {
                    "cpu": 1020,
                    "memory": 2048,
                    "worker_gpu_amount": 0,
                    "worker_npu_amount": 0
                },
                "worker_resource_spec": [
                    {
                        "cpu": 1000,
                        "memory": 2049,
                        "worker_gpu_amount": 0,
                        "worker_npu_amount": 0,
                        "worker_replicas": 1,
                        "enable_autoscaling": true,
                        "worker_min_replicas": 1,
                        "worker_max_replicas": 1
                    }
                ]
            },
            "rayjob_strategy": {
                "queued_timeout": 100000,
                "running_timeout": 100000
            }
        }
    }

    Table 1 describes the key parameters. For more information, see Running a Job.

    Table 1 Parameter description

    Parameter

    Description

    workspace_id

    Enter the workspace ID. For details about how to obtain a workspace ID, see Managing Workspaces.

    name

    Enter the job name.

    endpoint_name

    Enter the RayJob endpoint name. For details about how to obtain the RayJob endpoint name, see Managing a Ray Engine Endpoint.

    working_dir

    Enter the working directory where the code runs. This must be a remote URI, for example, an OBS path.

    entrypoint

    Enter the main script for running the job.

    image_id

    NOTE:
    • If the resource allocation mode of the endpoint is Hybrid or On-demand and an image snapshot is created for the selected image version, the snapshot is automatically associated when you select the image version. When the endpoint starts, the snapshot is automatically used to create image resources. No additional operation is required. For details about how to create an image snapshot, see Image Acceleration.
    • Built-in images are classified into CPU-only images (whose versions end with .cpu) and converged images. For CPU-only images, omitting GPU/NPU dependencies reduces image size, accelerates image pulling and startup, and improves resource utilization and task deployment efficiency.

    Enter the image version and ID. To view the image version and ID, perform the following steps:

    1. On the AI DataLake console, choose Image Management in the left navigation pane.
    2. On the Built-in Images or Custom Images tab, click the image name.
    3. Verify the version and ID of the built-in or custom image.
      • Check the built-in image version and ID: Click the Versions tab, and view the image version and ID in the Image Version/ID column.
      • Check the custom image version and ID: View the image version and ID in the Image Version/ID column. If no custom image is available, register one manually. For details, see Registering a Custom Image.

    image_version

  2. Check the returned response. A response similar to the following indicates that the RayJob endpoint is connected and the job is submitted:

    {
      "job_id" : "ac8111bf-3601-4905-8ddd-b41d3e63****"
    }

Related Operations