You need to enable JavaScript to run this app.
导航
SDK使用说明
最近更新时间:2024.09.13 14:40:49首次发布时间:2024.09.13 12:04:46

前置说明(必读)

以下内容为调用SDK的通用说明,以 智能绘图-通用2.0L-文生图 为例:
Step1: 查看接口文档请求参数-Query参数中的Action及对应Version,根据Action全局检索SDK,找到对应的example或参考本文档中的调用示例
图片
Step2: 查看接口文档请求参数-Body参数、请求示例,将请求示例内容复制到调用示例的body入参部分
图片
Step3: 更新其他关键信息,比如AK/SK,然后运行程序进行调试即可
图片

Step4: 调通SDK示例后,再正式集成到工程中

Java

SDK地址:https://github.com/volcengine/volc-sdk-java

同步接口(直接返回结果) Action=CVProcess

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-java/blob/main/example/src/main/java/com/volcengine/example/visual/CVProcessDemo.java

package com.volcengine.example.visual;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.volcengine.service.visual.IVisualService;
import com.volcengine.service.visual.impl.VisualServiceImpl;

public class CVProcessDemo {

    public static void main(String[] args) {
        IVisualService visualService = VisualServiceImpl.getInstance();
        // call below method if you dont set ak and sk in ~/.vcloud/config
        visualService.setAccessKey("your ak");
        visualService.setSecretKey("your sk");

        JSONObject req=new JSONObject();
        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        req.put("req_key","");
        req.put("","");

        try {
            Object response = visualService.cvProcess(req);
            System.out.println(JSON.toJSONString(response));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

异步提交任务(返回taskId) Action=CVSubmitTask

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-java/blob/main/example/src/main/java/com/volcengine/example/visual/CVSubmitTaskDemo.java

package com.volcengine.example.visual;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.volcengine.service.visual.IVisualService;
import com.volcengine.service.visual.impl.VisualServiceImpl;

public class CVSubmitTaskDemo {

    public static void main(String[] args) {
        IVisualService visualService = VisualServiceImpl.getInstance();
        // call below method if you dont set ak and sk in ~/.vcloud/config
        visualService.setAccessKey("your ak");
        visualService.setSecretKey("your sk");

        JSONObject req=new JSONObject();
        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        req.put("req_key","");
        req.put("","");

        try {
            Object response = visualService.cvSubmitTask(req);
            System.out.println(JSON.toJSONString(response));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

异步查询任务(返回结果) Action=CVGetResult

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-java/blob/main/example/src/main/java/com/volcengine/example/visual/CVGetResultDemo.java

package com.volcengine.example.visual;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.volcengine.service.visual.IVisualService;
import com.volcengine.service.visual.impl.VisualServiceImpl;
import com.volcengine.service.visual.model.request.VisualDistortionFreeRequest;
import com.volcengine.service.visual.model.response.VisualDistortionFreeResponse;

public class CVGetResultDemo {

    public static void main(String[] args) {
        IVisualService visualService = VisualServiceImpl.getInstance();
        // call below method if you dont set ak and sk in ~/.vcloud/config
        visualService.setAccessKey("your ak");
        visualService.setSecretKey("your sk");

        JSONObject req=new JSONObject();
        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        req.put("req_key","");
        req.put("","");

        try {
            Object response = visualService.cvGetResult(req);
            System.out.println(JSON.toJSONString(response));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

同步转异步提交任务(返回taskId)Action=CVSync2AsyncSubmitTask

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-java/blob/main/example/src/main/java/com/volcengine/example/visual/CVSync2AsyncSubmitTaskDemo.java

package com.volcengine.example.visual;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.volcengine.service.visual.IVisualService;
import com.volcengine.service.visual.impl.VisualServiceImpl;

public class CVSync2AsyncSubmitTaskDemo {

    public static void main(String[] args) {
        IVisualService visualService = VisualServiceImpl.getInstance();
        // call below method if you dont set ak and sk in ~/.vcloud/config
        visualService.setAccessKey("your ak");
        visualService.setSecretKey("your sk");

        JSONObject req=new JSONObject();
        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        req.put("req_key","");
        req.put("","");

        try {
            Object response = visualService.cvSync2AsyncSubmitTask(req);
            System.out.println(JSON.toJSONString(response));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

同步转异步查询任务(返回结果)Action=CVSync2AsyncGetResult

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-java/blob/main/example/src/main/java/com/volcengine/example/visual/CVSync2AsyncGetResultDemo.java

package com.volcengine.example.visual;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.volcengine.service.visual.IVisualService;
import com.volcengine.service.visual.impl.VisualServiceImpl;

public class CVSync2AsyncGetResultDemo {

    public static void main(String[] args) {
        IVisualService visualService = VisualServiceImpl.getInstance();
        // call below method if you dont set ak and sk in ~/.vcloud/config
        visualService.setAccessKey("your ak");
        visualService.setSecretKey("your sk");

        JSONObject req=new JSONObject();
        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        req.put("req_key","");
        req.put("","");

        try {
            Object response = visualService.cvSync2AsyncGetResult(req);
            System.out.println(JSON.toJSONString(response));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

Golang

SDK地址:https://github.com/volcengine/volc-sdk-golang

同步接口(直接返回结果) Action=CVProcess

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-golang/blob/main/example/visual/CVProcess.go

package main

import (
        "encoding/json"
        "fmt"

        "github.com/volcengine/volc-sdk-golang/service/visual"
)

func main() {
        testAk := "your ak"
        testSk := "your sk"

        visual.DefaultInstance.Client.SetAccessKey(testAk)
        visual.DefaultInstance.Client.SetSecretKey(testSk)
        //visual.DefaultInstance.SetRegion("region")
        //visual.DefaultInstance.SetHost("host")

        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        reqBody := map[string]interface{}{
                "req_key": ""
                // ...
        }
        
        resp, status, err := visual.DefaultInstance.CVProcess(reqBody)
        fmt.Println(status, err)
        b, _ := json.Marshal(resp)
        fmt.Println(string(b))
}

异步提交任务(返回taskId) Action=CVSubmitTask

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-golang/blob/main/example/visual/CVSubmitTask.go

package main

import (
        "encoding/json"
        "fmt"

        "github.com/volcengine/volc-sdk-golang/service/visual"
)

func main() {
        testAk := "your ak"
        testSk := "your sk"

        visual.DefaultInstance.Client.SetAccessKey(testAk)
        visual.DefaultInstance.Client.SetSecretKey(testSk)
        //visual.DefaultInstance.SetRegion("region")
        //visual.DefaultInstance.SetHost("host")

        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        reqBody := map[string]interface{}{
                "req_key":     ""
                // ...
        }

        resp, status, err := visual.DefaultInstance.CVSubmitTask(reqBody)
        fmt.Println(status, err)
        b, _ := json.Marshal(resp)
        fmt.Println(string(b))
}

异步查询任务(返回结果) Action=CVGetResult

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-golang/blob/main/example/visual/CVGetResult.go

package main

import (
        "encoding/json"
        "fmt"

        "github.com/volcengine/volc-sdk-golang/service/visual"
)

func main() {
        testAk := "your ak"
        testSk := "your sk"

        visual.DefaultInstance.Client.SetAccessKey(testAk)
        visual.DefaultInstance.Client.SetSecretKey(testSk)
        //visual.DefaultInstance.SetRegion("region")
        //visual.DefaultInstance.SetHost("host")

        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        reqBody := map[string]interface{}{
                "req_key": "",
                "task_id": ""
        }

        resp, status, err := visual.DefaultInstance.CVGetResult(reqBody)
        fmt.Println(status, err)
        b, _ := json.Marshal(resp)
        fmt.Println(string(b))
}

同步转异步提交任务(返回taskId) Action=CVSync2AsyncSubmitTask

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-golang/blob/main/example/visual/CVSync2AsyncSubmitTask.go

package main

import (
        "encoding/json"
        "fmt"

        "github.com/volcengine/volc-sdk-golang/service/visual"
)

func main() {
        testAk := "your ak"
        testSk := "your sk"

        visual.DefaultInstance.Client.SetAccessKey(testAk)
        visual.DefaultInstance.Client.SetSecretKey(testSk)
        //visual.DefaultInstance.SetRegion("region")
        //visual.DefaultInstance.SetHost("host")

        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        reqBody := map[string]interface{}{
                "req_key": ""
                //...
        }

        resp, status, err := visual.DefaultInstance.CVSync2AsyncSubmitTask(reqBody)
        fmt.Println(status, err)
        b, _ := json.Marshal(resp)
        fmt.Println(string(b))
}

同步转异步查询任务(返回结果) Action=CVSync2AsyncGetResult

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-golang/blob/main/example/visual/CVSync2AsyncGetResult.go

package main

import (
        "encoding/json"
        "fmt"

        "github.com/volcengine/volc-sdk-golang/service/visual"
)

func main() {
        testAk := "your ak"
        testSk := "your sk"

        visual.DefaultInstance.Client.SetAccessKey(testAk)
        visual.DefaultInstance.Client.SetSecretKey(testSk)
        //visual.DefaultInstance.SetRegion("region")
        //visual.DefaultInstance.SetHost("host")

        //请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
        reqBody := map[string]interface{}{
                "req_key": "",
                "task_id": ""
        }

        resp, status, err := visual.DefaultInstance.CVSync2AsyncGetResult(reqBody)
        fmt.Println(status, err)
        b, _ := json.Marshal(resp)
        fmt.Println(string(b))
}

Python

SDK地址:https://github.com/volcengine/volc-sdk-python

同步接口(直接返回结果) Action=CVProcess

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-python/blob/main/volcengine/example/visual/cv_process.py

# coding:utf-8
from __future__ import print_function

from volcengine.visual.VisualService import VisualService

if __name__ == '__main__':
    visual_service = VisualService()

    # call below method if you don't set ak and sk in $HOME/.volc/config
    visual_service.set_ak('your ak')
    visual_service.set_sk('your sk')
    
    # 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
    form = {
        "req_key": "xxx",
        # ...
    }

    resp = visual_service.cv_process(form)
    print(resp)

异步提交任务(返回taskId) Action=CVSubmitTask

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-python/blob/main/volcengine/example/visual/cv_submit_task.py

# coding:utf-8
from __future__ import print_function

from volcengine import visual
from volcengine.visual.VisualService import VisualService

if __name__ == '__main__':
    visual_service = VisualService()

    # call below method if you don't set ak and sk in $HOME/.volc/config
    visual_service.set_ak('your ak')
    visual_service.set_sk('your sk')
    
    # 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
    form = {
        "req_key": "xxx",
        # ...
    }
    resp = visual_service.cv_submit_task( form)
    print(resp)

异步查询任务(返回结果) Action=CVGetResult

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-python/blob/main/volcengine/example/visual/cv_get_result.py

# coding:utf-8
from __future__ import print_function

from volcengine import visual
from volcengine.visual.VisualService import VisualService

if __name__ == '__main__':
    visual_service = VisualService()

    # call below method if you don't set ak and sk in $HOME/.volc/config
    visual_service.set_ak('your ak')
    visual_service.set_sk('your sk')
    
    # 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
    form = {
        "req_key": "xxx",
        "task_id": "xxx"
    }
    resp = visual_service.cv_get_result(form)
    print(resp)

同步转异步提交任务(返回taskId)Action=CVSync2AsyncSubmitTask

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-python/blob/main/volcengine/example/visual/cv_sync2async_submit_task.py

# coding:utf-8
from __future__ import print_function

from volcengine import visual
from volcengine.visual.VisualService import VisualService

if __name__ == '__main__':
    visual_service = VisualService()

    # call below method if you don't set ak and sk in $HOME/.volc/config
    visual_service.set_ak('your ak')
    visual_service.set_sk('your ak')
    
    # 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
    form = {
        "req_key": "xxx",
        # ...

    }
    resp = visual_service.cv_sync2async_submit_task(form)
    print(resp)

同步转异步查询任务(返回结果)Action=CVSync2AsyncGetResult

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-python/blob/main/volcengine/example/visual/cv_sync2async_get_result.py

# coding:utf-8
from __future__ import print_function

from volcengine import visual
from volcengine.visual.VisualService import VisualService

if __name__ == '__main__':
    visual_service = VisualService()

    # call below method if you don't set ak and sk in $HOME/.volc/config
    visual_service.set_ak('your ak')
    visual_service.set_sk('your ak')
    
    # 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
    form = {
        "req_key": "xxx",
        "task_id": "xxx",
        "req_json": "{\"logo_info\":{\"add_logo\":true,\"position\":1, \"language\":1,\"opacity\":0.5}}"
    }
    resp = visual_service.cv_sync2async_get_result(form)
    print(resp)

PHP

SDK地址:https://github.com/volcengine/volc-sdk-php

同步接口(直接返回结果) Action=CVProcess

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-php/blob/main/examples/Visual/DemoCVProcess.php

<?php
require('../../../vendor/autoload.php');

use Volc\Service\Visual;

$client = Visual::getInstance();
// call below method if you dont set ak and sk in ~/.volc/config
$client->setAccessKey('your ak');
$client->setSecretKey('your sk');

echo "\nDemo CVProcess\n";

// 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
$body = [
    "req_key" => "xxx",
    //...
];

$response = $client->CVProcess(['json' => $body]);
$response = str_replace('\u0026', '&', $response);
echo $response;

异步提交任务(返回taskId) Action=CVSubmitTask

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-php/blob/main/examples/Visual/DemoCVSubmitTask.php

<?php
require('../../../vendor/autoload.php');

use Volc\Service\Visual;

$client = Visual::getInstance();
// call below method if you dont set ak and sk in ~/.volc/config
$client->setAccessKey('your ak');
$client->setSecretKey('your sk');

echo "\nDemo CVSubmitTask\n";

// 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
$body = [
    "req_key" =>  "xxx",
    //...
];

$response = $client->CVSubmitTask(['json' => $body]);
$response = str_replace('\u0026', '&', $response);
echo $response;

异步查询任务(返回结果) Action=CVGetResult

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-php/blob/main/examples/Visual/DemoCVGetResult.php

<?php
require('../../../vendor/autoload.php');

use Volc\Service\Visual;

$client = Visual::getInstance();
// call below method if you dont set ak and sk in ~/.volc/config
$client->setAccessKey('your ak');
$client->setSecretKey('your sk');

echo "\nDemo CVGetResult\n";

// 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
$body = [
    "req_key" => "xxx",
    "task_id" => "xxx"
];

$response = $client->CVGetResult(['json' => $body]);
$response = str_replace('\u0026', '&', $response);
echo $response;

同步转异步提交任务(返回taskId)Action=CVSync2AsyncSubmitTask

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-php/blob/main/examples/Visual/DemoCVSync2AsyncSubmitTask.php

<?php
require('../../../vendor/autoload.php');

use Volc\Service\Visual;

$client = Visual::getInstance();
// call below method if you dont set ak and sk in ~/.volc/config
$client->setAccessKey('your ak');
$client->setSecretKey('your sk');

echo "\nDemo CVSync2AsyncSubmitTask\n";

// 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
$body = [
    "req_key" => "xxx",
    //...
];

$response = $client->CVSync2AsyncSubmitTask(['json' => $body]);
$response = str_replace('\u0026', '&', $response);
echo $response;

同步转异步查询任务(返回结果)Action=CVSync2AsyncGetResult

调用示例

示例在SDK中的路径:https://github.com/volcengine/volc-sdk-php/blob/main/examples/Visual/DemoCVSync2AsyncGetResult.php

<?php
require('../../../vendor/autoload.php');

use Volc\Service\Visual;

$client = Visual::getInstance();
// call below method if you dont set ak and sk in ~/.volc/config
$client->setAccessKey('your ak');
$client->setSecretKey('your sk');

echo "\nDemo CVSync2AsyncGetResult\n";

// 请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
$body = [
    "req_key" => "xxx",
    "task_id" => "xxx",
    "req_json" => "{\"logo_info\":{\"add_logo\":true,\"position\":2,\"language\":0,\"opacity\":1}}"
];

$response = $client->CVSync2AsyncGetResult(['json' => $body]);
$response = str_replace('\u0026', '&', $response);
echo $response;