All Products
Search
Document Center

DataWorks:Use large language models

Last Updated:Jun 20, 2026

If network connectivity is established, you can use a deployed model in any DataWorks workspace within the same region. The following sections describe how to invoke and use a deployed large language model in DataWorks.

Prerequisites

Preparations

Before invoking a model, ensure that your application can access the large language model service. To invoke the model, obtain the model service endpoint and API key for identity authentication.

1. Configure network connectivity

Ensure that the VPC attached to your DataWorks resource group for model invocation is included in the list of VPCs allowed to connect to the model.

  1. Identify the first VPC attached to your resource group.

    1. Go to the DataWorks Resource Groups page. In the top navigation bar, switch to the region where your target resource group resides. Then, locate the resource group in the list.

    2. Click Operation in the row of the target resource group, then select Network Settings to open the VPC Binding page.

    3. Under Data Scheduling & Data Integration, view the corresponding vSwitch CIDR Block.

      Important

      When invoking a large language model, you must use the first VPC listed in the resource group’s network configuration as the communication foundation.

  2. To view the list of VPCs allowed to connect to the model or add a new VPC binding, see Manage model network.

2. Obtain invocation information

After deployment, the model service automatically generates an internal same-region endpoint. Go to the model service details page to retrieve this endpoint. The domain name format is: http://<model-service-id>.<region>.dataworks-model.aliyuncs.com. For instructions, see View model service.

3. Obtain an API key

Obtain your API key for authentication from Manage API Key.

Invoke large language model services

You can invoke large language models in Data Integration and Data Development to enable intelligent data processing.

Invoke in Data Integration

In offline sync tasks for single tables, you can apply AI-assisted processing to data during synchronization using a large language model service.

On the Configuration tab of the AI-assisted processing node, select a Model Provider (options include Alibaba Cloud DataWorks Model Service, Alibaba Cloud Model Studio, and Alibaba Cloud PAI Model Marketplace). Then configure the Model Name, Processing Task Description (for example, text translation, content summarization, or sentiment analysis), and Target Field.

Invoke in Data Development

1. Use a large language model node

DataWorks Data Development supports using a large language model node to process data. In this node, you can configure and invoke a large language model service.

2. Shell node invoking large language model

This example shows how to invoke a large language model from a Shell node to answer a specific question.

  1. Create a Shell node and add the following sample command:

    Note

    Replace the model service endpoint starting with http and the token starting with DW with the actual values you obtained in the Preparations section.

    curl -X POST http://ms-xxx.cn-beijing.dataworks-model.aliyuncs.com/v1/completions -H "Authorization: DW-ms-xxx" -H "Content-Type: application/json" -d '{"prompt":"Differences and connections among AI, machine learning, and deep learning", "stream":"false", "max_tokens": 1024}' -v    
  2. After editing the node, in the Run Configuration panel on the right side of the node editor, select the resource group that has completed network connectivity configuration with the model service.

  3. Click Run to invoke the deployed model service.

    Note
    • Node scheduling configuration: If the node needs to run on a schedule, select the resource group with completed network connectivity configuration in the Scheduling Settings panel on the right. Then configure scheduling properties in Scheduling Policy.

    • Node publishing: To run the task in a production environment, click the image icon in the interface to start the publishing workflow. Only after publishing to the production environment will the node run on a schedule.

3. Invoke a large language model with a Python node

This example shows how to invoke a large language model from a Python node to generate a poem.

  1. This example requires the Python requests library. Create a custom image based on an Alibaba Cloud Image to install this dependency. Use the following parameters:

    Custom image parameter

    Description

    Image name/ID

    Select a Python-compatible image from the DataWorks image list.

    Supported task type

    Select Python.

    Installation packages

    • Python3: requests.

    • Script: /home/tops/bin/pip3 install 'urllib3<2.0'.

  2. Create a Python node and add the following sample code:

    Note

    Replace the model service endpoint starting with http and the token starting with DW with the actual values you obtained in the Preparations section.

    import requests
    import json
    import time
    import sys
    def stream_print_response():
        httpUrl = "http://ms-xxxx.cn-beijing.dataworks-model.aliyuncs.com"
        apikey = "DW-ms-xxxx"
        url = httpUrl + "/v1/completions"
        headers = {
            "Authorization": apikey,
            "Content-Type": "application/json"
        }
        data = {
            "prompt": "Write a poem about spring",
            "stream": True,
            "max_tokens": 512
        }
        try:
            response = requests.post(url, headers=headers, json=data, stream=True)
            response.raise_for_status()
            full_text = ""  # Accumulate full response to prevent loss
            buffer = ""     # Optional: handle incomplete JSON lines
            for line in response.iter_lines():
                if not line:
                    continue  # Skip empty lines
                line_str = line.decode('utf-8').strip()
                # print(f"[DEBUG] Received line: {line_str}")  # For debugging
                if line_str.startswith("data:"):
                    data_str = line_str[5:].strip()  # Remove "data: "
                    if data_str == "[DONE]":
                        print("\n[Streaming response ended]")
                        break
                    # Attempt to parse JSON
                    try:
                        parsed = json.loads(data_str)
                        choices = parsed.get("choices", [])
                        if choices:
                            delta_text = choices[0].get("text", "")
                            if delta_text:
                                # Accumulate into full text
                                full_text += delta_text
                                # Print characters one by one
                                for char in delta_text:
                                    print(char, end='', flush=True)
                                    sys.stdout.flush()
                                    time.sleep(0.03)  # Typewriter effect
                    except json.JSONDecodeError as e:
                        # print(f"[Warning] JSON parsing failed: {e}, raw: {data_str}")
                        continue
            print(f"\n\n[Full response length: {len(full_text)} characters]")
            print(f"[ Full content]:\n{full_text}")
        except requests.exceptions.RequestException as e:
            print(f" Request failed: {e}")
        except Exception as e:
            print(f" Other error: {e}")
    if __name__ == "__main__":
        stream_print_response()
    
  3. After editing the node, in the Run Configuration panel on the right, select the resource group with completed network connectivity configuration and the custom Image from step 1 that includes the requests library.

  4. Click Run to invoke the deployed model service.

    Note
    • Node scheduling configuration: If the node needs to run on a schedule, select the resource group with completed network connectivity configuration and the custom Image from step 1 that includes the requests library in the Scheduling Settings panel. Then configure scheduling properties in Scheduling Policy.

    • Node publishing: To run the task in a production environment, click the image icon in the interface to start the publishing workflow. Only after publishing to the production environment will the node run on a schedule.

Invoke vector model services

You can invoke vector models in Data Integration and Data Development to perform vectorization on data. The following examples show how to invoke a BGE-M3 vector model service deployed on a DataWorks resource group.

Invoke in Data Integration

In offline sync tasks for single tables, you can apply vectorization to data during synchronization using a large model service.

After enabling the Data Processing toggle, add a Data Vectorization node to the processing list. In the configuration panel on the right, select a Model Provider (such as Alibaba Cloud DataWorks Model Service) and Model Name. Set the Batch Size, choose source fields to vectorize (column order affects the final result—drag to reorder), and enter a name for the Vectorized Result Field. You can also expand Advanced Options for additional settings.

Invoke in Data Development

1. LLM node invokes vector model service

DataWorks Data Development supports using a large model node to process data. In this node, you can configure and invoke a vector model service.

2. Shell node invokes vector model

This example shows how to convert text into vectors by invoking a vector model from a Shell node.

  1. Create a Shell node and add the following sample command:

    Note

    Replace the model service endpoint starting with http and the token starting with DW with the actual values you obtained in the Preparations section.

    curl -X POST "http://ms-xxx.cn-beijing.dataworks-model.aliyuncs.com/v1/embeddings" \
      -H "Authorization: DW-ms-xxx" \
      -H "Content-Type: application/json" \
      -d '{
        "input": "This is a piece of text that needs to be converted into a vector",
        "model": "bge-m3"
          }'
  2. After editing the node, in the Run Configuration panel on the right, select the resource group that has completed network connectivity configuration with the model service.

  3. Click Run to invoke the deployed model service.

    Note
    • Node scheduling configuration: If the node needs to run on a schedule, select the resource group with completed network connectivity configuration in the Scheduling Settings panel. Then configure scheduling properties in Scheduling Policy.

    • Node publishing: To run the task in a production environment, click the image icon in the interface to start the publishing workflow. Only after publishing to the production environment will the node run on a schedule.

3. Invoke a vector model from a Python node

This example shows how to convert text into vectors by invoking a vector model from a Python node.

  1. This example requires the Python requests library. Create a custom image based on an Alibaba Cloud Image to install this dependency. Use the following parameters:

    Custom image parameter

    Description

    Image name/ID

    Select a Python-compatible image from the DataWorks image list.

    Supported task type

    Select Python.

    Installation packages

    • Python3: requests.

    • Script: /home/tops/bin/pip3 install 'urllib3<2.0'.

  2. Create a Python node and add the following sample code:

    Note

    Replace the model service endpoint starting with http and the token starting with DW with the actual values you obtained in the Preparations section.

    import requests
    import json
    import sys
    # Replace with your API endpoint and token
    api_url = "http://ms-xxx.cn-beijing.dataworks-model.aliyuncs.com" + "/v1/embeddings"
    token = "DW-ms-xxx"
    print("api_url:"+api_url)
    print("token:"+token)
    headers = {
        "Authorization": f"{token}",
        "Content-Type": "application/json"
    }
    payload = {
        "input": "Test text",
        "model": "bge-m3"
    }
    try:
        response = requests.post(api_url, headers=headers, data=json.dumps(payload))
        print("Response status code:", response.status_code)
        print("Response content:", response.text)  # View detailed error messages
    except Exception as e:
        print("Request error:", e)
  3. After editing the node, in the Run Configuration panel on the right, select the resource group with completed network connectivity configuration and the custom Image from step 1 that includes the requests library.

  4. Click Run to invoke the deployed model service.

    Note
    • Node scheduling configuration: If the node needs to run on a schedule, select the resource group with completed network connectivity configuration in the Scheduling Settings panel. Then configure scheduling properties in Scheduling Policy.

    • Node publishing: To run the task in a production environment, click the image icon in the interface to start the publishing workflow. Only after publishing to the production environment will the node run on a schedule.

Related reading

For more details about commands for invoking large language models, see OpenAI-Compatible Server.