数分钟内完成你的首次 API 调用。
**体验中心**
“0”代码,交互式体验模型能力
**业务迁移**
兼容OpenAI API,快速迁移业务至方舟
# 1 获取并配置 API Key
1. 获取 API Key:访问[API Key 管理](https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey) ,创建你的 API Key。
2. 配置环境变量:在终端中运行下面命令,配置 API Key 到环境变量。
> 配置持久化环境变量方法参见 [环境变量配置指南](/docs/82379/1820161)。
```mixin-react
return (
);
```
# 2 开通模型服务
访问 [开通管理页面](https://console.volcengine.com/ark/region:ark+cn-beijing/openManagement) 开通模型服务。
# 3 安装 SDK
安装官方或三方 SDK。
```mixin-react
return (
运行环境中需安装 [Python](https://www.python.org/downloads/) 版本 3.7 或以上。
* 安装方舟 SDK:
\`\`\`Bash
pip install 'volcengine-python-sdk[ark]'
\`\`\`
* 安装 OpenAI SDK:
\`\`\`Bash
pip install openai
\`\`\`
`}>
环境中安装 [Go](https://golang.google.cn/doc/install) 版本 1.18 或以上。
在代码中通过下方方法引入 Go SDK
\`\`\`Go
import (
"github.com/volcengine/volcengine-go-sdk"
)
\`\`\`
`}>
环境中安装 [Java](https://www.java.com/en/download/help/index_installing.html) 版本 1.8 或以上。
在项目的\`pom.xml\`文件中添加以下依赖配置。
\`\`\`XML
com.volcengine
volcengine-java-sdk-ark-runtime
LATEST
\`\`\`
`}>);
```
# 4 发起 API 请求
## 文本生成
传入文本类信息给模型,进行问答、分析、改写、摘要、编程、翻译等任务,并返回文本结果。
```mixin-react
return (
);
```
* [文本生成](/docs/82379/1399009):文本生成使用指南。
* [深度思考](/docs/82379/1956279):深度思考能力使用指南。
* [迁移至 Responses API](/docs/82379/1585128):新用户推荐,更简洁的上下文管理能力、强大的工具调用能力。
* [Chat API](https://www.volcengine.com/docs/82379/1494384):存量业务迭代推荐,广泛使用的 API。
## 多模态理解
传入图片、视频、PDF文件给模型,进行分析、内容审核、问答、视觉定位等基于多模态理解相关任务,并返回文本结果。
|输入 |输出预览 |
|---|---|
| |* 思考:用户现在需要找支持输入图片的模型系列,看表格里的输入列中的图像列,哪个模型对应的图像输入是√。看表格,Doubao\-1.5\-vision那一行的输入图像列是√,其他两个Doubao\-1.5\-pro和lite的输入图像都是×,所以答案是Doubao\-1.5\-vision。|\
|> 支持输入图片的模型系列是哪个? |* 回答:支持输入图片的模型系列是Doubao\-1.5\-vision |
```mixin-react
return (
);
```
* [多模态理解](/docs/82379/1958521):多模态理解详细使用指南。
* [视觉定位 Grounding](/docs/82379/1616136):图片中找到对应目标并返回坐标任务。
* [GUI 任务处理](/docs/82379/1584296):在计算机/移动设备中完成自动化任务。
* [文件输入(File API)](/docs/82379/1885708):传入图片、视频、文档接口。
## 图片生成
传入图片、文字给模型,进行:广告、海报、组图等图片生成;增改元素、颜色更换等图片编辑;油墨、水墨等风格切换。
|提示词 |输出预览 |
|---|---|
|充满活力的特写编辑肖像,模特眼神犀利,头戴雕塑感帽子,色彩拼接丰富,眼部焦点锐利,景深较浅,具有Vogue杂志封面的美学风格,采用中画幅拍摄,工作室灯光效果强烈。 | |
```mixin-react
return (
);
```
* [Seedream 4.0-4.5 教程](/docs/82379/1824121):主流生图模型能力以及如何通过 API 调用。
* [Seedream 4.0-4.5 提示词指南](/docs/82379/1829186):使用生图模型时,如何编写提示词。
## 视频生成
通过文本描述、图像素材,快速生成高质量、风格多样的视频内容。
|提示词 |输出画面预览 |
|---|---|
|一位身穿绿色亮片礼服的女性站在粉红色背景前,周围飘落着五彩斑斓的彩纸 | |
```mixin-react
return (
contents = new ArrayList<>();
contents.add(Content.builder()
.type("text")
.text("一位身穿绿色亮片礼服的女性站在粉红色背景前,周围飘落着五彩斑斓的彩纸 --wm true --dur 5")
.build());
// Create a video generation task
CreateContentGenerationTaskRequest createRequest = CreateContentGenerationTaskRequest.builder()
.model("doubao-seedance-1-0-pro-250528") // Replace with Model ID
.content(contents)
.build();
CreateContentGenerationTaskResult createResult = service.createContentGenerationTask(createRequest);
System.out.println(createResult);
// Get the details of the task
String taskId = createResult.getId();
GetContentGenerationTaskRequest getRequest = GetContentGenerationTaskRequest.builder()
.taskId(taskId)
.build();
System.out.println("----- polling task status -----");
while (true) {
try {
GetContentGenerationTaskResponse getResponse = service.getContentGenerationTask(getRequest);
String status = getResponse.getStatus();
if ("succeeded".equalsIgnoreCase(status)) {
System.out.println("----- task succeeded -----");
System.out.println(getResponse);
service.shutdownExecutor();
break;
} else if ("failed".equalsIgnoreCase(status)) {
System.out.println("----- task failed -----");
System.out.println("Error: " + getResponse.getStatus());
service.shutdownExecutor();
break;
} else {
System.out.printf("Current status: %s, Retrying in 3 seconds...\\n", status);
TimeUnit.SECONDS.sleep(3);
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
System.err.println("Polling interrupted");
service.shutdownExecutor();
break;
}
}
}
}
\`\`\`
`}>
);
```
* [视频生成](/docs/82379/1366799):学习如何使用模型的视频生成能力,包括文本生成视频、首尾帧生视频、首帧生成视频等。
* [Seedance-1.0-pro&pro-fast 提示词指南](/docs/82379/1631633):使用生视频模型时,如何编写提示词。
## 工具使用
通过工具/插件让模型具体读取外部数据及函数的能力,包括
* 内置工具:联网搜索、图片处理、知识库检索等已集成至方舟平台的工具。
* 三方工具:兼容MCP 的三方工具。
* 自定义工具:您自行定义及开发的工具。
```mixin-react
return (
buildTools() {
ToolWebSearch t = ToolWebSearch.builder().build();
System.out.println(Arrays.asList(t));
return Arrays.asList(t);
}
public static void main(String[] args) throws JsonProcessingException {
String apiKey = System.getenv("ARK_API_KEY");
ArkService arkService = ArkService.builder().apiKey(apiKey).baseUrl("https://ark.cn-beijing.volces.com/api/v3").build();
CreateResponsesRequest req = CreateResponsesRequest.builder()
.model("doubao-seed-1-6-251015")
.input(ResponsesInput.builder().addListItem(
ItemEasyMessage.builder().role(ResponsesConstants.MESSAGE_ROLE_USER).content(
MessageContent.builder()
.addListItem(InputContentItemText.builder().text("What's the weather like in Beijing?").build())
.build()
).build()
).build())
.tools(buildTools())
.build();
ResponseObject resp = arkService.createResponse(req);
System.out.println(resp);
arkService.shutdownExecutor();
}
}
\`\`\`
`}>
);
```
* [工具调用](/docs/82379/1958524):学习如何让模型使用内置工具,如网页搜索、知识库检索、豆包助手等能力。
* [函数调用 Function Calling](/docs/82379/1262342):学习如何让模型调用自定义的工具。
* [云部署 MCP / Remote MCP](/docs/82379/1827534):学习如何让模型使用 MCP 服务。
# 5 下一步
现在你已经完成了首次方舟模型服务的 API 调用,你可以探索模型的更多能力,包括:
* [平台能力速览](/docs/82379/1108216):探索方舟平台提供的提示词优化、权限管理、模型管理等高阶能力。
* [模型列表](/docs/82379/1330310):快速浏览方舟提供的模型全集以及各个模型所具备的能力,快速根据你的实际场景匹配到合适的模型。