All Products
Search
Document Center

Alibaba Cloud Model Studio:Application calling

Last Updated:Nov 28, 2024

You can use SDK or HTTP to integrate applications to your business system. Agent application, workflow application, and agent orchestration application are all supported.

Prerequisites

You can call the applications through SDK or HTTP interfaces. Prepare your environment based on your needs.

Call method

Preparation

SDK

Install the SDK for Python or Java. For more information, see Install the SDK.

HTTP

To use HTTP, make the following configuration:

POST https://dashscope-intl.aliyuncs.com/api/v1/apps/{YOUR_APP_ID}/completion
No matter which method you use, we recommend that you set your API key as an environment variable.

Usage

Single-round conversation

Sample code for single-round conversation:

Python

Sample request:

from http import HTTPStatus
from dashscope import Application
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

response = Application.call(app_id='YOUR_APP_ID', prompt='Who are you?')

if response.status_code != HTTPStatus.OK:
    print(f'request_id={response.request_id}\ncode={response.status_code}\nmessage={response.message}\n')
else:
    print(f'request_id={response.request_id}\noutput={response.output}\nusage={response.usage}\n')

Sample response:

request_id=e3bba3a5-5784-9592-aa18-03170770de1e
output={"text": "I am a large language model from Alibaba Cloud, named Qwen. I can answer various questions, provide information, and engage in conversations with you. How can I assist you?", 
"finish_reason": "stop", "session_id": "a0606349b3c34c6fad7cf1d6454e0072", 
"thoughts": null, "doc_references": null}
usage={"models": [{"model_id": "qwen-max", "input_tokens": 121, "output_tokens": 37}]}

Java

Sample request:

// Recommended version of dashscope SDK >= 2.12.0
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import java.util.List;
import com.alibaba.dashscope.utils.Constants;

public class Main{
      static {
        Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
      }
      public static void appCall()
            throws ApiException, NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                .appId("YOUR_APP_ID")
                .prompt("Who are you?")
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());

        if (result.getUsage() != null && result.getUsage().getModels() != null) {
            for (ApplicationUsage.ModelUsage usage : result.getUsage().getModels()) {
                System.out.printf("modelId: %s, inputTokens: %d, outputTokens: %d\n",
                        usage.getModelId(), usage.getInputTokens(), usage.getOutputTokens());
            }
        }
    }

    public static void main(String[] args) {
        try {
            appCall();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            throw new RuntimeException(e);
        }
        System.exit(0);
    }  
}

Sample response:

requestId: 1458c2c0-05aa-9df3-9f99-e36d6a11cfbe, 
text: I am a language model from Alibaba Cloud, named Qwen. I am designed to help users obtain information, answer questions, and engage in conversations. How can I assist you?, 
finishReason: stop
modelId: qwen-max, inputTokens: 121, outputTokens: 34

cURL

Sample request:

curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/apps/YOUR_APP_ID/completion \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "input": {
        "prompt": "Who are you?"
    },
    "parameters":  {},
    "debug": {}
}' 

Sample response:

{"output":{"finish_reason":"stop",
"session_id":"232ea2e9e6ef448db6b14465c06a9a56",
"text":"I am a large language model from Alibaba Cloud, named Qwen. I am an AI assistant capable of answering questions, creating text, expressing opinions, and writing code. If you have any questions or need assistance, please feel free to let me know, and I will do my best to help you."},
"usage":{"models":[{"output_tokens":51,"model_id":"qwen-max","input_tokens":121}]},
"request_id":"661c9cad-e59c-9f78-a262-78eff243f151"}% 

Multi-round conversation

In multi-round conversations, the LLM can reference the conversation history, making it more similar to everyday communication scenarios.

Use the session_id returned from a previous call as an input parameter for subsequent calls to maintain session continuity.

Note: Only agent applications and dialog workflow applications support multi-round conversations.

Python

Sample request:

from http import HTTPStatus
from dashscope import Application
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

def call_with_session():
    response = Application.call(app_id='YOUR_APP_ID',
                                prompt='I want to visit Singapore')

    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
        return response

    response1 = Application.call(app_id='YOUR_APP_ID',
                                 prompt='What are the attractions and foods there?',
                                 session_id=response.output.session_id)
    if response1.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response1.request_id, response1.status_code, response1.message))
    else:
        print('request_id=%s\n output=%s\n usage=%s\n' % (response1.request_id, response1.output, response1.usage))


if __name__ == '__main__':
    call_with_session()

Sample response:

request_id=a9d3f1b1-6745-981a-af82-9ec58522d78f
 output={"text": "Singapore is famous for its diverse attractions and a vibrant food scene that reflects its multicultural heritage. 
 Here are some popular attractions and must-try foods:\n\n
 **Attractions:**\n\n
 1. **Merlion Park**: Home to the iconic Merlion statue, a half-lion, half-fish symbol of Singapore.\n\n
 2. **Botanic Gardens**: A lush green space featuring a variety of plants, including the National Orchid Garden.\n\n
 3. **Marina Bay Sands**: An integrated resort with luxury shopping, dining, a casino, and a breathtaking infinity pool.\n\n
 4. **Gardens by the Bay**: A futuristic garden with massive Supertrees, two cooled conservatories (Flower Dome and Cloud Forest), and nightly light shows.\n\n
 5. **Sentosa Island**: An entertainment hub with beaches, theme parks (Universal Studios Singapore), Madame Tussauds, and the S.E.A. Aquarium.\n\n
 6. **Orchard Road**: Singapore's premier shopping district lined with malls, boutiques, restaurants, and entertainment venues.\n\n
 7. **Chinatown, Little India, and Kampong Glam**: Cultural enclaves offering a glimpse into Singapore's ethnic diversity through architecture, markets, and food.\n\n
 8. **National Museum of Singapore**: A museum showcasing Singapore's history and cultural heritage.\n\n
 **Foods:**\n\n
 1. **Hainanese Chicken Rice**: A national dish consisting of poached chicken served with fragrant rice cooked in chicken broth, accompanied by chili sauce and ginger paste.\n\n
 2. **Laksa**: A spicy noodle soup typically made with coconut milk, shrimp or fish, and a blend of spices.\n\n
 3. **Chilli Crab**: Fresh crabs cooked in a sweet and savory tomato and chili-based sauce, often eaten with mantou (deep-fried buns).\n\n
 4. **Char Kway Teow**: Stir-fried rice noodles with egg, Chinese sausage, bean sprouts, and cockles, seasoned with dark soy sauce and chili.\n\n
 5. **Satay**: Grilled skewered meat (usually chicken, beef, or mutton) served with peanut sauce and cucumber slices.\n\n
 6. **Nasi Lemak**: A Malay dish of fragrant coconut rice served with fried anchovies, peanuts, egg, and sambal chili paste, often accompanied by a side of chicken or fish.\n\n
 7. **Roti Prata**: A flaky Indian-style flatbread usually served with curry or sugar for dipping.\n\n
 8. **Kaya Toast**: Traditional breakfast item featuring toast filled with a spread made from coconut jam and butter, typically paired with soft-boiled eggs and coffee or tea.\n\n
 These are just a few highlights; Singapore's food scene is incredibly diverse, and exploring hawker centers like Maxwell Food Centre, Lau Pa Sat, or Tiong Bahru Market is a must for any food enthusiast.", 
 "finish_reason": "stop", 
 "session_id": "443f935a8d80496f94dcfa4a04b7edfa", 
 "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", 
 "input_tokens": 688, 
 "output_tokens": 423}]}

Java

Sample request:

import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;

import java.util.Arrays;
import java.util.List;
import com.alibaba.dashscope.utils.Constants;

public class Main {
      static {
        Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
      }
      public static void callWithSession()
            throws ApiException, NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                .appId("YOUR_APP_ID")
                .prompt("I want to visit Singapore")
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        param.setSessionId(result.getOutput().getSessionId());
        param.setPrompt("What are the attractions and foods there?");
        result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());
    }
  
   public static void main(String[] args) {
        try {
            callWithSession();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }  
}

Sample response:

requestId: 440a0772-3c67-922e-8acb-d90840b96217, text: Singapore is a vibrant city-state brimming with exciting attractions and a rich culinary scene. Here are some must-visit attractions and must-try foods:

### Tourist Attractions

1. **Merlion Park**: Home to the iconic Merlion statue, a half-lion, half-fish symbol of Singapore.
2. **Botanic Gardens**: A UNESCO World Heritage Site featuring lush gardens, including the National Orchid Garden.
3. **Universal Studios Singapore**: Located on Sentosa Island, it offers thrilling rides and entertainment based on popular movies.\n\n4. **National Museum of Singapore**: A fascinating insight into the country's history and culture.
4. **Clarke Quay**: A lively riverside area filled with restaurants, bars, and entertainment venues.
5. **National Museum of Singapore**: A fascinating insight into the country's history and culture.
6. **Singapore Flyer**: A giant observation wheel offering panoramic views of the city skyline.
7. **ArtScience Museum**: Unique exhibitions that blend art, science, and technology.

### Food Recommendations

1. **Hainanese Chicken Rice** - Poached chicken, fragrant rice in chicken broth, chili sauce, ginger paste.
2. **Laksa** - Spicy coconut noodle soup with shrimp, cockles, fish cakes.
3. **Chilli Crab** - Fresh crab in sweet, tangy, spicy tomato sauce; mantou.
4. **Satay** - Grilled marinated meat skewers, peanut sauce, cucumber relish.
5. **Char Kway Teow** - Stir-fried flat rice noodles, prawns, cockles, veggies, soy-chili.
6. **Roti Prata** - Crispy flatbread, curry/sugar, plain/egg/cheese-filled options.
7. **Fish Head Curry** - Spicy, aromatic fish head curry with veggies, tamarind twist.
8. **Kaya Toast** - Toast with kaya (coconut jam), soft-boiled eggs, coffee/tea.
9. **Nasi Lemak** - Coconut rice, fried chicken, anchovies, peanuts, cucumber, sambal.
10. **Durian Desserts** - Durian ice cream, pastries, fresh fruit for the adventurous., finishReason: stop

cURL

Sample request (previous call):

curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/apps/YOUR_APP_ID/completion \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "input": {
        "prompt": "I want to visit Singapore"
    },
    "parameters":  {},
    "debug": {}
}' 

Sample response (previous call):

{"output":{"finish_reason":"stop",
"session_id":"d380aeb21d4b4b018f1d7ae9f98de404",
"text":"Visiting Singapore is a great choice! It's a vibrant city-state known for its multiculturalism, modern architecture, delicious food, and lush green spaces. Here’s a guide to help you plan your trip:\nWhen to Go\nBest Time: November to January (cooler and less humid)\nAvoid: June to August (hot and humid, plus it's peak tourist season)\nGetting There\nBy Air: Changi Airport is one of the world's best airports. Many international airlines fly to Singapore.\nBy Sea: You can also arrive by cruise ship or ferry from neighboring countries like Malaysia and Indonesia.\nWhere to Stay\nLuxury: Marina Bay Sands, Raffles Hotel\nMid-Range: Hotel Indigo, Park Hotel"},
"usage":{"models":[{"output_tokens":389,"model_id":"qwen-max","input_tokens":51}]},
"request_id":"a1e8cbb2-51dc-9733-a97c-e7ca5a7f0438"}%   

Sample request (subsequent call):

curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/apps/YOUR_APP_ID/completion \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "input": {
        "prompt": "What are the foods there?",
        "session_id":"d380aeb21d4b4b018f1d7ae9f98de404"
    },
    "parameters":  {},
    "debug": {}
}' 

Sample response (subsequent call):

{"output":{"finish_reason":"stop",
"session_id":"d380aeb21d4b4b018f1d7ae9f98de404",
"text":"Here are some authentic foods you must try when you visit Singapore:\n\n
**Hainanese Chicken Rice** - Poached chicken, fragrant rice in chicken broth, chili sauce, ginger paste.
2. **Laksa** - Spicy coconut noodle soup with shrimp, cockles, fish cakes.
3. **Chilli Crab** - Fresh crab in sweet, tangy, spicy tomato sauce; mantou.
4. **Satay** - Grilled marinated meat skewers, peanut sauce, cucumber relish.
5. **Char Kway Teow** - Stir-fried flat rice noodles, prawns, cockles, veggies, soy-chili.
6. **Roti Prata** - Crispy flatbread, curry/sugar, plain/egg/cheese-filled options.
7. **Fish Head Curry** - Spicy, aromatic fish head curry with veggies, tamarind twist.
8. **Kaya Toast** - Toast with kaya (coconut jam), soft-boiled eggs, coffee/tea.
9. **Nasi Lemak** - Coconut rice, fried chicken, anchovies, peanuts, cucumber, sambal.
10. **Durian Desserts** - Durian ice cream, pastries, fresh fruit for the adventurous.
"usage":{"models":[{"output_tokens":411,"model_id":"qwen-max","input_tokens":454}]},
"request_id":"366d21f5-1a4a-9fe5-8ba2-e7955ff8cd23"}% 

Streaming output

In streaming output mode, the LLM generates and returns intermediate results in real-time instead of one final response. This reduces the wait time for the complete response.

Python

Sample request:

from http import HTTPStatus
from dashscope import Application
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

responses = Application.call(app_id='YOUR_APP_ID',
                             prompt='Who are you?',
                             stream=True,
                             incremental_output=True)

for response in responses:
    if response.status_code != HTTPStatus.OK:
        print(f'request_id={response.request_id}\ncode={response.status_code}\nmessage={response.message}\n')
    else:
        print(f'request_id={response.request_id}\noutput={response.output}\nusage={response.usage}\n')

Sample response:

request_id=b63c8c47-f4bd-9fa0-9cfc-f06da91588fe
 output={"text": "I am", "finish_reason": "null", "session_id": "42ece8924aa842a3b55405b6ddf97429", "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", "input_tokens": 142, "output_tokens": 1}]}

request_id=b63c8c47-f4bd-9fa0-9cfc-f06da91588fe
 output={"text": "from", "finish_reason": "null", "session_id": "42ece8924aa842a3b55405b6ddf97429", "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", "input_tokens": 142, "output_tokens": 2}]}

request_id=b63c8c47-f4bd-9fa0-9cfc-f06da91588fe
 output={"text": "Alibaba", "finish_reason": "null", "session_id": "42ece8924aa842a3b55405b6ddf97429", "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", "input_tokens": 142, "output_tokens": 3}]}

request_id=b63c8c47-f4bd-9fa0-9cfc-f06da91588fe
 output={"text": "Cloud's language model assistant,", "finish_reason": "null", "session_id": "42ece8924aa842a3b55405b6ddf97429", "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", "input_tokens": 142, "output_tokens": 8}]}

request_id=b63c8c47-f4bd-9fa0-9cfc-f06da91588fe
 output={"text": "I am called Qwen. I can", "finish_reason": "null", "session_id": "42ece8924aa842a3b55405b6ddf97429", "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", "input_tokens": 142, "output_tokens": 16}]}

request_id=b63c8c47-f4bd-9fa0-9cfc-f06da91588fe
 output={"text": "answer various questions, provide information, and", "finish_reason": "null", "session_id": "42ece8924aa842a3b55405b6ddf97429", "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", "input_tokens": 142, "output_tokens": 24}]}

request_id=b63c8c47-f4bd-9fa0-9cfc-f06da91588fe
 output={"text": "perform tasks like dialogue. I am happy to serve you!", "finish_reason": "null", "session_id": "42ece8924aa842a3b55405b6ddf97429", "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", "input_tokens": 142, "output_tokens": 32}]}

request_id=b63c8c47-f4bd-9fa0-9cfc-f06da91588fe
 output={"text": "Is there anything I can help you with?", "finish_reason": "null", "session_id": "42ece8924aa842a3b55405b6ddf97429", "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", "input_tokens": 142, "output_tokens": 37}]}

request_id=b63c8c47-f4bd-9fa0-9cfc-f06da91588fe
 output={"text": "", "finish_reason": "stop", "session_id": "42ece8924aa842a3b55405b6ddf97429", "thoughts": null, "doc_references": null}
 usage={"models": [{"model_id": "qwen-max", "input_tokens": 142, "output_tokens": 37}]}

Java

Sample request:

import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import io.reactivex.Flowable;

import java.util.Arrays;
import java.util.List;

import com.alibaba.dashscope.utils.Constants;

public class Main {
      static {
        Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
      }
      public static void streamCall() throws NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                .appId("YOUR_APP_ID")
                .prompt("Who are you?")
                .incrementalOutput(true)
                .build();

        Application application = new Application();
        Flowable<ApplicationResult> result = application.streamCall(param);
        result.blockingForEach(data -> {
            System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                    data.getRequestId(), data.getOutput().getText(), data.getOutput().getFinishReason());

        });
    }

    public static void main(String[] args) {
        try {
		        streamCall();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }
}

Sample response:

requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: I am, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: from, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: Alibaba, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: Cloud's large language, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: model, I am called Qwen, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: . I can generate various types of text, such as, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: articles, stories, poems, stories, etc., finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: and can transform and extend according to different scenarios and needs. In addition, I can also, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: answer various questions, provide help and solutions, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: . If you have any questions or need help, please, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: feel free to tell me!, finishReason: null
requestId: a36ae034-bc33-91d0-a50f-3f4051211303, text: , finishReason: stop

cURL

Sample request:

curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/apps/YOUR_APP_ID/completion \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--header 'X-DashScope-SSE: enable' \
--data '{
    "input": {
        "prompt": "Who are you?"
    },
    "parameters":  {},
    "debug": {}
}' 

Sample response:

id:1
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am"},"usage":{"models":[{"input_tokens":184,"output_tokens":1,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:2
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am from"},"usage":{"models":[{"input_tokens":184,"output_tokens":2,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:3
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am from Alibaba"},"usage":{"models":[{"input_tokens":184,"output_tokens":3,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:4
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am from Alibaba Cloud's large language"},"usage":{"models":[{"input_tokens":184,"output_tokens":8,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:5
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am from Alibaba Cloud's large language model, I am called Qwen"},"usage":{"models":[{"input_tokens":184,"output_tokens":16,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:6
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am from Alibaba Cloud's large language model, I am called Qwen. I can generate text, answer questions,"},"usage":{"models":[{"input_tokens":184,"output_tokens":24,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:7
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am from Alibaba Cloud's large language model, I am called Qwen. I can generate text, answer questions, create stories, write code, translate, and perform various"},"usage":{"models":[{"input_tokens":184,"output_tokens":32,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:8
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am from Alibaba Cloud's large language model, I am called Qwen. I can generate text, answer questions, create stories, write code, translate, and perform various language tasks. If you have any questions or need"},"usage":{"models":[{"input_tokens":184,"output_tokens":40,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:9
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am from Alibaba Cloud's large language model, I am called Qwen. I can generate text, answer questions, create stories, write code, translate, and perform various language tasks. If you have any questions or need help, please feel free to let me know, and I will do my best to provide"},"usage":{"models":[{"input_tokens":184,"output_tokens":48,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:10
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"null","text":"I am from Alibaba Cloud's large language model, I am called Qwen. I can generate text, answer questions, create stories, write code, translate, and perform various language tasks. If you have any questions or need help, please feel free to let me know, and I will do my best to provide support."},"usage":{"models":[{"input_tokens":184,"output_tokens":50,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}

id:11
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"909ece989f1e4c59b416743abefc8a45","finish_reason":"stop","text":"I am from Alibaba Cloud's large language model, I am called Qwen. I can generate text, answer questions, create stories, write code, translate, and perform various language tasks. If you have any questions or need help, please feel free to let me know, and I will do my best to provide support."},"usage":{"models":[{"input_tokens":184,"output_tokens":50,"model_id":"qwen-max"}]},"request_id":"e7dde240-6f52-9cf0-a70f-d2a4b94374c5"}
The sample responses above are from an agent application. For workflow applications and agent orchestration applications, streaming output responses are returned in thoughts.

Custom parameter pass-through

In the following main scenarios, you may need to pass custom parameters:

  • Custom plugin parameters and authentication for agent applications.

  • Custom input parameters for workflow applications and agent orchestration applications.

You can use biz_params to pass parameters in both scenarios. For more information, see Parameter pass-through for applications.

  • Workflow applications and agent orchestration applications support custom parameters in start nodes. For example, to query city administrative divisions in a workflow application, set the variable 'city' and define a String type parameter city for pass-through during the call.

  • For agent applications, the fixed parameter user_defined_params is used to deliver parameter information. The fixed parameter user_defined_tokens is used to deliver authentication information for user-level authentication of custom plug-ins, where the fixed field user_token is the authentication Token. For more information, see the following example of dormitory convention.

    Python

    Workflow and agent orchestration application

    Sample request:

    from http import HTTPStatus
    from dashscope import Application
    import dashscope
    dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
    
    # Custom input parameter pass-through for workflow and agent orchestration applications
    biz_params = {"city": "Singapore"}
    
    response = Application.call(
        app_id='YOUR_APP_ID',
        prompt='Query the administrative divisions of this city',
        biz_params=biz_params  # Pass business parameters
    )
    
    if response.status_code != HTTPStatus.OK:
        print(f'request_id={response.request_id}, code={response.status_code}, message={response.message}')
    else:
        print(f'output={response.output}, usage={response.usage}')
    

    Sample response:

    output={"text": "Singapore is a city-state, which means it is both a city and an independent sovereign state. It does not have the typical administrative divisions like provinces or states that larger countries might have. Instead, for administrative purposes, Singapore is divided into five regions, and further subdivided into planning areas. Here are the five regions:
    Central Region, East Region, North Region, North-East Region, West Region", 
    "finish_reason": "stop", "session_id": "6a3bf88eacda43128f57d87e29323166", 
    "thoughts": null, "doc_references": null}, usage={"models": null}

    Custom plugin parameter

    Sample request:

    from http import HTTPStatus
    # Recommended version of dashscope SDK >= 1.14.0
    from dashscope import Application
    import dashscope
    dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
    
    biz_params = {
        # Custom plugin input parameter pass-through for agent applications, replace {your_plugin_code} with your custom plugin ID
        "user_defined_params": {
            "{your_plugin_code}": {
                "article_index": 2}}}
    response = Application.call(app_id='YOUR_APP_ID',
                                prompt='Dormitory convention content',
                                biz_params=biz_params)
    
    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
    else:
        print('request_id=%s\n output=%s\n usage=%s\n' % (response.request_id, response.output, response.usage))
    

    Sample response:

    request_id=d97e3c58-7a75-9ea1-9ecf-d5be869b748e
     output={"text": "The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely. This reminds us to maintain good interpersonal relationships in dormitory life and create a harmonious and positive living and learning environment together. If you need to know more about the convention, please tell me the specific number or continue to ask questions.", "finish_reason": "stop", "session_id": "8ec3fa6c59794ed3ab803b921aa38d7a", "thoughts": null, "doc_references": null}
     usage={"models": [{"model_id": "qwen-max", "input_tokens": 453, "output_tokens": 107}]}

    Custom plugin authentication

    Sample request:

    from http import HTTPStatus
    # Recommended version of dashscope SDK >= 1.14.0
    from dashscope import Application
    import dashscope
    dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
    
    biz_params = {
        # Custom plugin authentication pass-through for agent applications, replace {your_plugin_code} with your custom plugin ID, and token with YOUR_TOKEN
        "user_defined_params": {
            "{your_plugin_code}": {
                "article_index": 2}},
        "user_defined_tokens": {
            "{your_plugin_code}": {
                "user_token": "YOUR_TOKEN"}}}
    response = Application.call(app_id='YOUR_APP_ID',
                                prompt='Dormitory convention content',
                                biz_params=biz_params)
    
    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
    else:
        print('request_id=%s\n output=%s\n usage=%s\n' % (response.request_id, response.output, response.usage))
    

    Sample response:

    request_id=e928fe3b-3df3-9a3f-9ea4-884aed3aea3c
     output={"text": "The second article of the dormitory convention is: 'Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely.' This emphasizes the importance of establishing harmonious, supportive, and respectful relationships among dormitory members.", "finish_reason": "stop", "session_id": "c3b909e48a0b4867a57b482dece9cbb7", "thoughts": null, "doc_references": null}
     usage={"models": [{"model_id": "qwen-max", "input_tokens": 432, "output_tokens": 82}]}

    Java

    Workflow and agent orchestration application

    Sample request:

    package org.example;
    
    import com.alibaba.dashscope.app.*;
    import com.alibaba.dashscope.exception.ApiException;
    import com.alibaba.dashscope.exception.InputRequiredException;
    import com.alibaba.dashscope.exception.NoApiKeyException;
    import com.alibaba.dashscope.utils.JsonUtils;
    
    import io.reactivex.Flowable;
    
    
    import com.alibaba.dashscope.utils.Constants;
    
    public class Main {
        static {
            Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
        }
        public static void streamCall() throws NoApiKeyException, InputRequiredException {
    
            String bizParams =
                    "{\"city\":\"Singapore\"}";
            ApplicationParam param = ApplicationParam.builder()
                    .appId("YOUR_APP_ID")
                    .prompt("Query the administrative divisions of this city")
                    .bizParams(JsonUtils.parse(bizParams))
                    .build();
    
            Application application = new Application();
            Flowable<ApplicationResult> result = application.streamCall(param);
            result.blockingForEach(data -> {
                System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                        data.getRequestId(), data.getOutput().getText(), data.getOutput().getFinishReason());
    
            });
        }
    
        public static void main(String[] args) {
            try {
                streamCall();
            } catch (ApiException | NoApiKeyException | InputRequiredException e) {
                System.out.printf("Exception: %s", e.getMessage());
            }
            System.exit(0);
        }
    }

    Sample response:

    requestId: 713ebb6e-8840-9f31-bd58-e7e931ef345d, 
    text: conventione is a city-state, which means it is both a city and an independent sovereign state. It does not have the typical administrative divisions like provinces or states that larger countries might have. Instead, for administrative purposes, Singapore is divided into five regions, and further subdivided into planning areas. Here are the five regions: Central Region, East Region, North Region, North-East Region, West Region, 
    finishReason: stop
    

    Custom plugin parameter

    Sample request:

    package org.example;
    
    import com.alibaba.dashscope.app.*;
    import com.alibaba.dashscope.exception.ApiException;
    import com.alibaba.dashscope.exception.InputRequiredException;
    import com.alibaba.dashscope.exception.NoApiKeyException;
    import com.alibaba.dashscope.utils.JsonUtils;
    
    import io.reactivex.Flowable;
    import com.alibaba.dashscope.utils.Constants;
    
    class Main {
        static {
            Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
        }
        public static void streamCall() throws NoApiKeyException, InputRequiredException {
    
            String bizParams =
                    "{\"user_defined_params\":{\"{your_plugin_code}\":{\"article_index\":2}}}";
            ApplicationParam param = ApplicationParam.builder()
                    .appId("YOUR_APP_ID")
                    .prompt("Dormitory convention content")
                    .bizParams(JsonUtils.parse(bizParams))
                    .build();
    
            Application application = new Application();
            Flowable<ApplicationResult> result = application.streamCall(param);
            result.blockingForEach(data -> {
                System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                        data.getRequestId(), data.getOutput().getText(), data.getOutput().getFinishReason());
    
            });
        }
    
        public static void main(String[] args) {
            try {
                streamCall();
            } catch (ApiException | NoApiKeyException | InputRequiredException e) {
                System.out.printf("Exception: %s", e.getMessage());
            }
            System.exit(0);
        }
    }

    Sample response:

    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: Dorm, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely., finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely. This emphasizes the importance of harmonious coexistence and mutual progress among dormitory members. If you need, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely. This emphasizes the importance of harmonious coexistence and mutual progress among dormitory members. If you need to know other articles, please tell me the number, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely. This emphasizes the importance of harmonious coexistence and mutual progress among dormitory members. If you need to know other articles, please tell me the number., finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely. This emphasizes the importance of harmonious coexistence and mutual progress among dormitory members. If you need to know other articles, please tell me the number., finishReason: stop
    

    Custom plugin authentication

    Sample request:

    package org.example;
    
    import com.alibaba.dashscope.app.*;
    import com.alibaba.dashscope.exception.ApiException;
    import com.alibaba.dashscope.exception.InputRequiredException;
    import com.alibaba.dashscope.exception.NoApiKeyException;
    import com.alibaba.dashscope.utils.JsonUtils;
    
    import io.reactivex.Flowable;
    import com.alibaba.dashscope.utils.Constants;
    
    class Main {
        static {
            Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
        }
        public static void streamCall() throws NoApiKeyException, InputRequiredException {
    
            String bizParams =
                    "{\"user_defined_params\":{\"{your_plugin_code}\":{\"article_index\":2}}," +
                            "\"user_defined_tokens\":{\"{your_plugin_code}\":{\"user_token\":\"YOUR_TOKEN\"}}}";
            ApplicationParam param = ApplicationParam.builder()
                    .appId("YOUR_APP_ID")
                    .prompt("Dormitory convention content")
                    .bizParams(JsonUtils.parse(bizParams))
                    .build();
    
            Application application = new Application();
            Flowable<ApplicationResult> result = application.streamCall(param);
            result.blockingForEach(data -> {
                System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                        data.getRequestId(), data.getOutput().getText(), data.getOutput().getFinishReason());
    
            });
        }
    
        public static void main(String[] args) {
            try {
                streamCall();
            } catch (ApiException | NoApiKeyException | InputRequiredException e) {
                System.out.printf("Exception: %s", e.getMessage());
            }
            System.exit(0);
        }
    }

    Sample response:

    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: Dorm, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely., finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely. This emphasizes the importance of harmonious coexistence and mutual progress among dormitory members. If you need, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely. This emphasizes the importance of harmonious coexistence and mutual progress among dormitory members. If you need to know other articles, please tell me the number, finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely. This emphasizes the importance of harmonious coexistence and mutual progress among dormitory members. If you need to know other articles, please tell me the number., finishReason: null
    requestId: 48bb400a-d050-9f5c-afbd-c1adb25f6a43, text: The second article of the dormitory convention states: Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely. This emphasizes the importance of harmonious coexistence and mutual progress among dormitory members. If you need to know other articles, please tell me the number., finishReason: stop
    

    cURL

    Workflow and agent orchestration application

    Sample request:

    curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/apps/YOUR_APP_ID/completion \
    --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
    --header 'Content-Type: application/json' \
    --data '{
        "input": {
            "prompt": "Query the administrative divisions of this city",
            "biz_params": {
            "city": "convention"}
        },
        "parameters":  {}
    }'
    

    Sample response:

    {"output":{"finish_reason":"stop","session_id":"c211219896004b50a1f6f66f2ec5413e",
    "text":"Singapore is a city-state, which means it is both a city and an independent sovereign state. It does not have the typical administrative divisions like provinces or states that larger countries might have. Instead, for administrative purposes, Singapore is divided into five regions, and further subdivided into planning areas. Here are the five regions: Central Region, East Region, North Region, North-East Region, West Region"},"usage":{},
    "request_id":"02c3c9e1-7912-9505-91aa-248d04fb1f5d"}

    Custom plugin parameter

    Sample request:

    curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/apps/YOUR_APP_ID/completion \
    --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
    --header 'Content-Type: application/json' \
    --data '{
        "input": {
            "prompt": "Dormitory convention content",
            "biz_params": 
            {
                "user_defined_params":
                {
                    "{your_plugin_code}":
                        {
                        "article_index": 2
                        }
                }
            } 
        },
        "parameters":  {},
        "debug":{}
    }'

    Sample response:

    {"output":
    {"finish_reason":"stop",
    "session_id":"e151267ffded4fbdb13d91439011d31e",
    "text":"The second article of the dormitory convention is: 'Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely.' This means that in dormitory life, everyone should support each other and create a harmonious and positive living environment together."},
    "usage":{"models":[{"output_tokens":94,"model_id":"qwen-max","input_tokens":453}]},
    "request_id":"a39fd2b5-7e2c-983e-84a1-1039f726f18a"}%

    Custom plugin authentication

    Sample request:

    curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/apps/YOUR_APP_ID/completion \
    --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
    --header 'Content-Type: application/json' \
    --data '{
        "input": {
            "prompt": "Dormitory convention content",
            "biz_params": 
            {
                "user_defined_params":
                {
                    "{your_plugin_code}":
                        {
                        "article_index": 2
                        }
                },
                "user_defined_tokens":
                {
                    "{your_plugin_code}":
                        {
                        "user_token": "YOUR_TOKEN"
                        }
                }
            } 
        },
        "parameters":  {},
        "debug":{}
    }'
    
    
    

    Sample response:

    {"output":{"finish_reason":"stop",
    "session_id":"d3b5c3e269dc40479255a7a02df5c630",
    "text":"The second article of the dormitory convention states: 'Dormitory members should help each other, care for each other, learn from each other, and improve together; be tolerant and modest, respect each other, and treat each other sincerely.' This emphasizes the importance of harmonious coexistence and mutual progress among dormitory members."},
    "usage":{"models":[{"output_tokens":80,"model_id":"qwen-max","input_tokens":432}]},
    "request_id":"1f77154c-edc3-9003-b622-816fa2f849cf"}%

Knowledge base filtering

When the Knowledge Retrieval Enhancement feature is enabled for an agent application or a Knowledge Base Node is established in a workflow application, you can define the retrieval scope when calling the application.

  • To retrieve a specific knowledge Base, input the knowledge base ID.

    • You can find the knowledge base ID on the knowledge index page or by using the CreateIndex API, which returns Data.Id.

      Note: The API can create only unstructured knowledge bases.
    • The retrieved knowledge base is not necessarily the knowledge base associated with the agent application.

    • Only the specified knowledge base is accessed. For example, if knowledge base A is associated with the agent application but only knowledge base B is specified in the API call, only knowledge base B retrieved.

  • To retrieve specific unstructured documents, specify the ID, tag, or metadata of the document.

    • You can find the document IDs on the Data Management page.

    • You can specify multiple document IDs. But only documents inside a knowledge base can be retrieved.

    • If you specify a document ID, you must also specify the corresponding knowledge base ID.

    • Only the specified document is accessed. For example, if knowledge base A is associated with the agent application but a document in knowledge base B is specified in the API call, only the document in knowledge base B retrieved. In this case, both the document ID and the ID of knowledge base B are required.

Note: Only HTTP calls support knowledge filtering

Specify knowledge base

Sample request:

curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/apps/{YOUR_APP_ID}/completion \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "input": {
        "prompt": "Please recommend a phone under 3000 RMB"
    },
    "parameters":  {
                    "rag_options" : {
                    "pipeline_ids":["your_pipeline_id1"]}
    },
    "debug": {}
}'

Sample response:

{"output":{"finish_reason":"stop","session_id":"d1208af96f9a4d8390e9b29e86f0623c",
"text":"In the price range under 3000 RMB, I recommend the Bailian Zephyr Z9. This phone is priced between 2499 and 2799 RMB, perfectly meeting your budget requirements. It features a lightweight 6.4-inch 1080 x 2340 pixel display, with 128GB of storage space and 6GB of RAM, sufficient for handling various applications and multitasking in daily use. Additionally, it is equipped with a 4000mAh battery, ensuring a full day of use without worries, and a 30x digital zoom lens for capturing life's details. Overall, the Bailian Zephyr Z9 is a good choice in terms of cost-effectiveness, design, and functionality."},
"usage":{"models":[{"output_tokens":158,"model_id":"qwen-max","input_tokens":1025}]},
"request_id":"eb2d40f7-bede-9d48-88dc-08abdcdd0351"}% 

Specify unstructured document

Sample request:

curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/apps/{YOUR_APP_ID}/completion \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "input": {
        "prompt": "Please recommend a phone around 3000 RMB"
    },
    "parameters":  {
                    "rag_options" : {
                    "pipeline_ids":["your_pipeline_id1"],
                    "metadata_filter":{
                    "name":"Tom"},
                    "tags":"phone"
                    }
    },
    "debug": {}
}'

Sample response:

{"output":{"finish_reason":"stop","session_id":"f2f114864dd24a458f923aab0ec99a1d",
"text":"Based on your budget, I recommend considering the 'Tongyi Vivid 7.' It features a 6.5-inch 1080 x 2400 pixel full-screen display with AI smart photography capabilities, allowing you to capture photos with professional-grade color and detail. Its hardware configuration includes 8GB RAM and 128GB storage space, ensuring a smooth operating experience; the 4500mAh battery capacity can also meet daily usage needs. Additionally, the side fingerprint unlock design is both convenient and secure. The reference price is between 2999 and 3299 RMB, fitting within your budget range."},
"usage":{"models":[{"output_tokens":141,"model_id":"qwen-plus","input_tokens":1610}]},
"request_id":"d815d3d1-8cef-95e2-b895-89fc8d0e0f84"}%      
The document ID, tag, and metadata are only applicable to unstructured knowledge bases.

Request and response parameters

To view the request and response parameters, see Application API reference.

FAQ

  1. What to do if I receive an error stating "java: package com.alibaba.dashscope.app does not exist" while executing Java code examples?

    1. Verify the accuracy of class and package names in your import statements.

    2. If you use Maven or Gradle, make sure that the Java SDK dependency is included and up-to-date in the pom.xml or build.gradle file of your project. Visit Maven for the latest SDK version.

      <!-- https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
      <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>dashscope-sdk-java</artifactId>
          <version>Fill in the latest version number here, for example, 2.16.4</version>
      </dependency>
      // https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java
      implementation group: 'com.alibaba', name: 'dashscope-sdk-java', version: 'Fill in the latest version number here, for example, 2.16.4'
    3. Update the SDK: If you are using an older version of the Java SDK, it may lack necessary features or classes. Update the SDK version in your pom.xml or build.gradle file to the latest release.

      <!-- https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
      <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>dashscope-sdk-java</artifactId>
          <version>Fill in the latest version number here, for example, 2.16.4</version>
      </dependency>
      // https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java
      implementation group: 'com.alibaba', name: 'dashscope-sdk-java', version: 'Fill in the latest version number here, for example, 2.16.4'
    4. Reload the project for the changes to take effect.

    5. Execute the sample code again.

      If the problem persists, submit a ticket to request additional support or visit the developer community to check if similar problems have been reported and their corresponding solutions.