跳到正文
博客

只需改一行代码,即可从 DeepL API 迁移

将官方 DeepL SDK(Python、Node、.NET、Java、PHP 或 Ruby)指向 VibeQL。您的调用方式、字段名和错误处理都保持不变。

VibeQL 创始人Alisson Leal

发布于 4 分钟阅读

VibeQL 能响应与 DeepL API 相同的请求。路径相同(/v2/translate、/v2/document、/v2/usage、/v2/languages),JSON 字段名相同,错误码也相同:密钥无效返回 403,配额用尽返回 456,文件过大返回 413。

因此您不需要新的 SDK。每个官方 DeepL 客户端库都有服务器 URL 选项。将其设为 https://vibeql.com,使用 VibeQL API 密钥,其余代码保持不变。

各语言中的那一行代码

示例会将文本和文档翻译成巴西葡萄牙语。只有客户端初始化部分发生变化,下面的调用都是常规的 SDK 调用。

import os
import deepl

client = deepl.DeepLClient(
    os.environ["VIBEQL_API_KEY"],
    server_url="https://vibeql.com",
)

result = client.translate_text("Hello, world", target_lang="PT-BR")
print(result.text)

client.translate_document_from_filepath(
    "report.docx", "report.pt-BR.docx", target_lang="PT-BR"
)
import * as deepl from "deepl-node";

const client = new deepl.DeepLClient(process.env.VIBEQL_API_KEY, {
  serverUrl: "https://vibeql.com",
});

const result = await client.translateText("Hello, world", null, "pt-BR");
console.log(result.text);

await client.translateDocument("report.docx", "report.pt-BR.docx", null, "pt-BR");
using DeepL;

var client = new DeepLClient(
    Environment.GetEnvironmentVariable("VIBEQL_API_KEY"),
    new DeepLClientOptions { ServerUrl = "https://vibeql.com" });

var result = await client.TranslateTextAsync("Hello, world", null, "pt-BR");
Console.WriteLine(result.Text);

await client.TranslateDocumentAsync(
    new FileInfo("report.docx"), new FileInfo("report.pt-BR.docx"), null, "pt-BR");
import com.deepl.api.*;
import java.io.File;

DeepLClientOptions options = new DeepLClientOptions().setServerUrl("https://vibeql.com");
DeepLClient client = new DeepLClient(System.getenv("VIBEQL_API_KEY"), options);

TextResult result = client.translateText("Hello, world", null, "pt-BR");
System.out.println(result.getText());

client.translateDocument(new File("report.docx"), new File("report.pt-BR.docx"), null, "pt-BR");
$client = new \DeepL\DeepLClient(getenv('VIBEQL_API_KEY'), [
    'server_url' => 'https://vibeql.com',
]);

$result = $client->translateText('Hello, world', null, 'pt-BR');
echo $result->text;

$client->translateDocument('report.docx', 'report.pt-BR.docx', null, 'pt-BR');
require 'deepl'

client = DeepL::Client.new(ENV.fetch('VIBEQL_API_KEY'), server_url: 'https://vibeql.com')

translation = client.translate_text 'Hello, world', nil, 'PT-BR'
puts translation.text
package main

import (
	"bytes"
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	body := []byte(`{"text":["Hello, world"],"target_lang":"PT-BR"}`)
	req, _ := http.NewRequest("POST", "https://vibeql.com/v2/translate", bytes.NewReader(body))
	req.Header.Set("Authorization", "DeepL-Auth-Key "+os.Getenv("VIBEQL_API_KEY"))
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	out, _ := io.ReadAll(res.Body)
	fmt.Println(string(out))
}

各语言说明:

  • Python、Node、PHP。 该选项在 Python 和 PHP 中为 server_url,在 Node 中为 serverUrl。旧版 Translator 类接受相同的选项,因此仍在使用它的代码也能正常工作。
  • .NET 和 Java。 在 .NET 中该选项是 DeepLClientOptions 上的 ServerUrl,在 Java 中是 setServerUrl()。构建 TranslatorOptions 的旧代码也有相同的设置。
  • Ruby。 DeepL::Client.new 接受 server_url:。如果您的代码使用模块级 DeepL.configure 块,请在那里设置 config.host = 'https://vibeql.com'。
  • Go。 DeepL 没有官方 Go SDK,因此示例直接发送 HTTP 请求。如果第三方 Go 客户端允许您设置基础 URL,也可以使用。

我们于 2026 年 11 月在 GitHub 上的官方 SDK README 中核对了这些选项名称。

以以下内容结尾的密钥 :fx

DeepL Free 密钥以 :fx 结尾,SDK 根据该后缀选择 api-free.deepl.com。一旦设置了服务器 URL,SDK 就会将每个请求发送到该 URL,因此后缀不再起作用。VibeQL 密钥以 vql_ 开头。检查 :fx 的代码可以保留,但不会产生任何影响。

身份验证

VibeQL 接受 DeepL 请求头 Authorization: DeepL-Auth-Key <key>,因此 SDK 无需更改即可使用。它还接受 Authorization: Bearer <key> 和旧版 auth_key 表单字段。完整列表请参阅身份验证。

哪些保持不变

  • 使用 /v2/translate 进行文本翻译,包括在一个请求中翻译多段文本。
  • 使用 /v2/document 的上传、状态查询和下载步骤进行文档翻译。封装这些步骤的 SDK 辅助方法可直接使用。
  • /v2/usage 以及 /v2/languages 和 /v3/languages。
  • 语言代码。VibeQL 使用 DeepL 的代码,例如 PT-BR、EN-US 和 ZH-HANS。完整列表见语言。
  • 状态码和错误响应体,因此您的重试和配额逻辑仍然有效。

有哪些不同

还有其他不同之处需要了解:

  • 定价。VibeQL 没有每份文档 50,000 字符的最低限制。您按文件中的字符数付费。示例见DeepL 最低收费的实际成本,套餐见定价。
  • 文件格式。VibeQL 可翻译 DOCX、PPTX、PDF 和 TXT 文件。其他格式会返回错误。
  • 文件大小。API 套餐接受最大 50 MB 的文件。免费套餐接受最大 10 MB、10 页的文件。见限制与错误。
  • 文件会过期。翻译后的文件在上传后保留 24 小时。请在此期间下载结果。
  • 扫描版 PDF。VibeQL 暂不支持 OCR,因此没有文本层的扫描版 PDF 没有可翻译的内容。

切换前先测试

您可以同时运行两个服务。使用 VibeQL 服务器 URL 创建第二个客户端,把真实流量中的样本同时发送给两者,然后比较结果。准备好后,修改配置中的服务器 URL 并部署。如需回退,移除该选项即可。

后续步骤

获取 API 密钥

每月 500,000 个免费 API 字符。

账户就绪后会发送一封邮件,之后大约每月发送一封产品邮件。