应用部署
应用部署介绍
应用部署功能为开发者提供快速将应用发布API的能力。支持开发者将公开应用部署为服务API,并支持公网调用,以及查看服务API调用详情。
使用流程
1. 选择需要部署的应用
进入应用中心,选择需要部署的应用。
2. 点击应用部署
点击右上角部署按钮,即可将应用部署为服务,您可以在服务详情页查看部署详情,包括运行状态、时长、API调用次数、消耗等。
计费方式:基于对话式应用部署的服务将按照实际调用消耗token,基于AI绘画类应用部署的服务将按照调用次数消耗A币。
服务运行中,您可以停止服务,需要的时候您可以点击【重启】来恢复您的服务。同时,您也可以删除服务,一旦删除无法恢复,请您谨慎操作。
API服务使用文档
服务部署后,请您前往 https://aistudio.baidu.com/index/accessToken 查看您的访问令牌。
用您的访问令牌,替换调
# 请前往 https://aistudio.baidu.com/index/accessToken 查看 访问令牌
curl --location 'https://{appCode}-aistudio-hub.baidu.com/image/generations' \
--header 'Authorization: token <access-token>' \
--header 'Content-Type: application/json' \
--data '{
"prompt":"杰作,高品质,超精细,全细节,8k"
}'
AI对话类
请求说明
- 基本信息
请求地址:https://{appCode}.aistudio-hub.baidu.com/chat/completions
请求方式: POST
- Header参数
- message说明
响应说明
usage说明
请求示例
注意将appCode替换成真实的服务ID
单轮
curl --location 'https://{appCode}.aistudio-hub.baidu.com/chat/completions' \
--header 'Authorization: token <access_token>' \
--header 'Content-Type: application/json' \
--data '{
"messages":[
{
"role":"user",
"content": "hello world"
}
],
"top_p": 0.8
}'
回复
{
"id": "f4f4e96034e4eb9438193accf2b5bc8d",
"object": "chat.completion",
"created": 1700636952,
"result": "Hello World 是一种经典的计算机程序,通常用于演示编程语言的基本语法和结构。下面是一个简单的 Hello World 程序的示例:\n\n\n```java\npublic class HelloWorld {\n public static void main(String[] args) {\n System.out.println(\"Hello, World!\");\n }\n}\n```\n这个程序的作用是在屏幕上输出 \"Hello, World!\" 的消息。通过这个程序,初学者可以学习如何编写一个简单的程序,并了解计算机程序的基本概念和结构。",
"usage": {
"prompt_tokens": 2,
"completion_tokens": 107,
"total_tokens": 109
},
"need_clear_history": false,
"is_truncated": false
}
流式
curl --location 'https://{appCode}.aistudio-hub.baidu.com/chat/completions' \
--header 'Authorization: token <access-token>' \
--header 'Content-Type: application/json' \
--data '{
"stream": true,
"messages":[
{
"role":"user",
"content": "hello world"
}
]
}'
回复
data:{"id":"as-fyh4usk720","object":"chat.completion","created":1700637054,"sentence_id":0,"is_end":false,"is_truncated":false,"result":"看起来您只是想打印 \"","need_clear_history":false,"finish_reason":"normal","usage":{"prompt_tokens":2,"completion_tokens":0,"total_tokens":2}}
data:{"id":"as-fyh4usk720","object":"chat.completion","created":1700637054,"sentence_id":1,"is_end":false,"is_truncated":false,"result":"Hello, World!\" 字符串。","need_clear_history":false,"finish_reason":"normal","usage":{"prompt_tokens":2,"completion_tokens":0,"total_tokens":2}}
data:{"id":"as-fyh4usk720","object":"chat.completion","created":1700637056,"sentence_id":2,"is_end":false,"is_truncated":false,"result":"这是一个常见的程序任务,经常在初学者的编程教程中作为第一个例子出现。","need_clear_history":false,"finish_reason":"normal","usage":{"prompt_tokens":2,"completion_tokens":0,"total_tokens":2}}
data:{"id":"as-fyh4usk720","object":"chat.completion","created":1700637061,"sentence_id":3,"is_end":false,"is_truncated":false,"result":"\n\n以下是在几种常见编程语言中打印 \"Hello, World!\" 的方法:\n\n1. Python\n\n\n```python\nprint(\"Hello, World!\")\n```\n2. Java\n\n\n```java\npublic class Main {\n public static void main(String[] args) {\n System","need_clear_history":false,"finish_reason":"normal","usage":{"prompt_tokens":2,"completion_tokens":0,"total_tokens":2}}
data:{"id":"as-fyh4usk720","object":"chat.completion","created":1700637065,"sentence_id":4,"is_end":false,"is_truncated":false,"result":".out.println(\"Hello, World!\");\n }\n}\n```\n3. C++\n\n\n```cpp\n#include \u003ciostream\u003e\nint main() {\n std::cout \u003c\u003c \"Hello, World!\";\n return 0;\n}\n```\n4. JavaScript (","need_clear_history":false,"finish_reason":"normal","usage":{"prompt_tokens":2,"completion_tokens":0,"total_tokens":2}}
data:{"id":"as-fyh4usk720","object":"chat.completion","created":1700637068,"sentence_id":5,"is_end":false,"is_truncated":false,"result":"可以在网页浏览器中运行)\n\n\n```javascript\nconsole.log(\"Hello, World!\");\n```\n如果您需要在其他编程语言中完成这个任务,或者您的要求比这个更复杂,欢迎您提出更具体的问题。","need_clear_history":false,"finish_reason":"normal","usage":{"prompt_tokens":2,"completion_tokens":0,"total_tokens":2}}
data:{"id":"as-fyh4usk720","object":"chat.completion","created":1700637068,"sentence_id":6,"is_end":true,"is_truncated":false,"result":"","need_clear_history":false,"finish_reason":"normal","usage":{"prompt_tokens":2,"completion_tokens":208,"total_tokens":210}}
AI绘画类
请求说明
- 基本信息
请求地址:https://{appCode}.aistudio-hub.baidu.com/image/generations
请求方式:POST
- Header参数
- Body参数
响应说明
image_data说明
usage说明
请求示例
注意将appCode替换成真实的服务ID
请求
curl --location 'https://{appCode}.aistudio-hub.baidu.com/image/generations' \
--header 'Authorization: token <access_token>' \
--header 'Content-Type: application/json' \
--data '{"seed":111,"n":2,
"prompt":"杰作,高品质,超精细,全细节,8k",
"n": 1
}'
回复
{
"id": "f4f4e96034e4eb9438193accf2b5bc8d",
"object": "image",
"created": 1700636952,
"data": [
{
"object": "image",
"b64_image": "图片base64编码",
"index": 1
}
],
"usage": {
"total_acoin": 1
}
}
错误返回
示例
{
"logId": "f024a5f86764eb0ca38a4d5f89176ca2",
"errorCode": 336000,
"errorMsg": "Internal error"
}
错误码定义
注意事项
如服务所关联的源应用被删除,该服务也会自动【下线】,为了提供开发者稳定的应用服务,目前发布后的应用不支持开发者手动删除,如有特殊情况(侵权、黄暴等)请邮件联系(aistudio@baidu.com)官方平台,我们将在第一时间为您处理,感谢您的理解与支持。
更多文档
更多应用创建的详细步骤请参考 零代码应用开发文档 。