跳至主要內容
部落格

只要改一行,就能從 DeepL API 遷移過來

把 DeepL 官方的 Python、Node、.NET、Java、PHP 或 Ruby SDK 指向 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 字元。

帳戶開通後會寄一封電子郵件,之後大約每月一封產品通知。