Prompt 翻译 Prompt Translation
专为 AI Prompt 优化翻译,智能保留指令结构、格式标签和上下文逻辑。 Translation optimized for AI prompts. Intelligently preserves instruction structure, formatting, and contextual logic.
快速概览
Quick Overview
Prompt 翻译 API 专为 AI 应用场景设计,在翻译系统 Prompt、用户提示词、模型指令时自动识别并保留占位符 {{var}}、Markdown/XML 格式标签、Few-shot 示例结构等关键元素。支持按目标模型(通义千问、文心一言 等)针对性优化译文的指令遵循度。单次最多处理 50,000 字符。
The Prompt Translation API is purpose-built for AI scenarios. It automatically identifies and preserves placeholders {{var}}, Markdown/XML format tags, few-shot example structures, and other critical elements when translating system prompts, user prompts, and model instructions. Supports target-model-specific optimization (Qwen, ERNIE, etc.) for instruction-following accuracy. Processes up to 50,000 characters per request.
请求端点 Endpoint
POST /v1/prompt/translate
认证方式 Authentication
所有 Prompt 翻译接口均需要在 HTTP 请求头中携带有效的 API Token 进行身份认证。请在 控制台 获取您的 Access Token。
All Prompt Translation endpoints require a valid API Token in the HTTP request header for authentication. Obtain your Access Token from the Console .
Authorization: Bearer <YOUR_ACCESS_TOKEN>
请求头 Request Headers
Header Header 类型 Type 必填 Required 说明 Description
Authorizationstring required Bearer Token 认证信息 Bearer token authentication
Content-Typestring required 请求体格式,固定为 application/json Request body format; fixed to application/json
请求参数 Request Parameters
参数 Parameter 类型 Type 必填 Required 说明 Description
prompt string required 待翻译的 Prompt 文本,最长 50,000 字符 Prompt text to translate; max 50,000 chars
source_lang string required 源语言代码,支持 auto 自动检测 Source language code; supports auto for detection
target_lang string required 目标语言代码 Target language code
preserve_format boolean optional 保留 Markdown/XML/HTML 格式标签,默认 true Preserve Markdown/XML/HTML formatting; default true
preserve_placeholders boolean optional 识别并保留占位符(如 {{var}}、${name}),默认 true Recognize and preserve placeholders (e.g. {{var}}, ${name}); default true
model_context string optional 目标模型,如 qwen-max / ernie-4,辅助优化译文指令遵循度 Target model (e.g. qwen-max, ernie-4) for optimizing instruction-following
prompt_type string optional Prompt 类型:system / user / assistant / few_shot,影响翻译策略 Prompt type: system / user / assistant / few_shot; affects translation strategy
custom_variables array optional 自定义变量名列表,API 会保留这些变量不被翻译,如 ["user_name", "product_name"] Custom variable names to preserve as-is during translation, e.g. ["user_name", "product_name"]
glossary_id string optional 关联术语库 ID,确保特定术语的翻译一致性 Linked glossary ID for consistent term translation
domain string optional 领域:general / code / medical / legal / finance / game Domain: general / code / medical / legal / finance / game
自动保留元素 Auto-Preserved Elements
Prompt 翻译引擎在翻译时会自动识别并保留以下元素,确保翻译后的 Prompt 与原始 Prompt 在逻辑和结构上完全等效。
The Prompt translation engine automatically identifies and preserves the following elements during translation, ensuring logical and structural equivalence with the original prompt.
元素类型 Element Type 示例 说明 Description
占位符 Placeholders {{question}}, {{user_input}}, ${var}, %NAME%双花括号模板变量、Shell 风格、百分比风格占位符 Double-brace template vars, shell-style, percent-style placeholders
Markdown 标记 Markdown Tags **bold**, ### Heading, - list, `code`标题、列表、加粗、行内代码等 Markdown 语法 Headings, lists, bold, inline code, and other Markdown syntax
XML/HTML 标签 XML/HTML Tags <context>...</context>, <instruction>结构化标签保留结构,仅翻译内容文本 Structural tags preserved; only content text is translated
代码块 Code Blocks ```python ... ```, `var_name`围栏代码块和行内代码内容不翻译 Fenced code blocks and inline code content are not translated
JSON/YAML 字段 JSON/YAML Keys {"role": "user", "content": "..."}结构化数据的 key 保持不变,value 按需翻译 Structured data keys preserved; values translated as needed
Few-shot 分隔符 Few-shot Separators Q:, A:, ---, Example 1:保留示例分隔符结构,确保 few-shot 格式一致 Example separator structure preserved for consistent few-shot format
目标模型上下文参考 Model Context Reference
model_context 提供商 Provider 优化策略 Optimization Strategy
qwen-max阿里云 适配通义千问指令模板,优化分隔符和角色标记 Adapt to Qwen instruction templates; optimize separators and role markers
ernie-4-turbo百度 适配文心一言紧凑指令格式,减少冗余描述 Adapt to compact instruction format for ERNIE; minimize verbose descriptions
glm-4智谱AI 适配 GLM XML 标签风格,优化结构化提示 Adapt to GLM XML tag style; optimize structured prompts
deepseek-v2DeepSeek 适配 DeepSeek 对话格式,优化角色轮次标记 Adapt to DeepSeek conversation format; optimize role turn markers
baichuan-3百川智能 适配百川特殊 token 和指令模板 Adapt to Baichuan special tokens and instruction templates
auto通用 Generic 通用优化,不绑定特定模型 General optimization; not model-specific
请求示例 Request Examples
cURL
Python
JavaScript
Java
Go
# 基础 Prompt 翻译
curl -X POST https://api.itranslator.cc/v1/prompt/translate \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"prompt": "You are a helpful assistant. Answer concisely.\n\nQ: {{question}}\nA:",
"source_lang": "en",
"target_lang": "zh",
"preserve_format": true,
"model_context": "qwen-max"
}'
# 复杂 System Prompt + 术语库 + 自定义变量保护
curl -X POST https://api.itranslator.cc/v1/prompt/translate \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"prompt": "You are a {{role}} specializing in {{domain}}. Follow these rules:\n1. Always reference the block\n2. Use **bold** for key terms\n3. Output in ```json``` format\n\nExample:\nQ: What is {{term}}?\nA: {\"definition\": \"...\", \"source\": \"{{source}}\"}",
"source_lang": "en",
"target_lang": "ja",
"preserve_format": true,
"preserve_placeholders": true,
"prompt_type": "system",
"custom_variables": ["term", "source"],
"glossary_id": "gls_ai_terms",
"model_context": "glm-4",
"domain": "general"
}'
import requests
# 基础翻译
payload = {
"prompt": "You are a helpful assistant. Answer concisely.\n\nQ: {{question}}\nA:",
"source_lang": "en",
"target_lang": "zh",
"preserve_format": True,
"model_context": "qwen-max"
}
resp = requests.post(
"https://api.itranslator.cc/v1/prompt/translate",
headers={"Authorization": f"Bearer {token}"},
json=payload
)
print(resp.json())
# 复杂 System Prompt + 变量保护 + 术语库
payload2 = {
"prompt": (
"You are a {{role}} specializing in {{domain}}. Follow these rules:\n"
"1. Always reference the block\n"
"2. Use **bold** for key terms\n"
"3. Output in ```json``` format\n\n"
'Example:\n'
"Q: What is {{term}}?\n"
'A: {"definition": "...", "source": "{{source}}"}'
),
"source_lang": "en",
"target_lang": "ja",
"preserve_format": True,
"preserve_placeholders": True,
"prompt_type": "system",
"custom_variables": ["term", "source"],
"glossary_id": "gls_ai_terms",
"model_context": "glm-4",
"domain": "general"
}
resp2 = requests.post(
"https://api.itranslator.cc/v1/prompt/translate",
headers={"Authorization": f"Bearer {token}"},
json=payload2
)
print(resp2.json())
// 基础翻译
const payload = {
prompt: "You are a helpful assistant. Answer concisely.\n\nQ: {{question}}\nA:",
source_lang: "en",
target_lang: "zh",
preserve_format: true,
model_context: "qwen-max"
};
const resp = await fetch("https://api.itranslator.cc/v1/prompt/translate", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
console.log(await resp.json());
// 复杂 System Prompt + 变量保护 + 术语库
const payload2 = {
prompt: 'You are a {{role}} specializing in {{domain}}. Follow these rules:\n1. Always reference the block\n2. Use **bold** for key terms\n3. Output in ```json``` format\n\nExample:\nQ: What is {{term}}?\nA: {"definition": "...", "source": "{{source}}"}',
source_lang: "en",
target_lang: "ja",
preserve_format: true,
preserve_placeholders: true,
prompt_type: "system",
custom_variables: ["term", "source"],
glossary_id: "gls_ai_terms",
model_context: "glm-4",
domain: "general"
};
const resp2 = await fetch("https://api.itranslator.cc/v1/prompt/translate", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify(payload2)
});
console.log(await resp2.json());
import com.google.gson.Gson;
import java.util.*;
Gson gson = new Gson();
Map<String, Object> payload = new HashMap<>();
payload.put("prompt", "You are a helpful assistant. Answer concisely.\n\nQ: {{question}}\nA:");
payload.put("source_lang", "en");
payload.put("target_lang", "zh");
payload.put("preserve_format", true);
payload.put("model_context", "qwen-max");
RequestBody body = RequestBody.create(
gson.toJson(payload), MediaType.parse("application/json"));
Request request = new Request.Builder()
.url("https://api.itranslator.cc/v1/prompt/translate")
.header("Authorization", "Bearer " + token)
.post(body)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
payload := map[string]interface{}{
"prompt": "You are a helpful assistant. Answer concisely.\n\nQ: {{question}}\nA:",
"source_lang": "en",
"target_lang": "zh",
"preserve_format": true,
"model_context": "qwen-max",
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST",
"https://api.itranslator.cc/v1/prompt/translate",
bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
fmt.Println(resp.Status)
}
响应字段 Response Fields
字段 Field 类型 Type 说明 Description
code integer 状态码,0 表示成功 Status code; 0 = success
message string 操作结果描述 Result description
data.translated_prompt string 翻译后的 Prompt 文本,保留原始结构和占位符 Translated prompt with original structure and placeholders preserved
data.preserved_elements array 已保留的元素列表(占位符、标签、分隔符等) List of preserved elements (placeholders, tags, separators, etc.)
data.source_lang string 实际使用的源语言代码 Actual source language code used
data.target_lang string 目标语言代码 Target language code
data.format_preserved boolean 格式标签是否全部保留成功 Whether all format tags were successfully preserved
data.placeholders_preserved integer 成功保留的占位符数量 Number of placeholders successfully preserved
响应示例 Response Examples
示例 1:基础 Prompt 翻译 Example 1: Basic Prompt Translation
{
"code": 0,
"message": "success",
"data": {
"translated_prompt": "你是一个乐于助人的助手。请以简洁准确的方式回答以下问题。\n\nQ: {{question}}\nA:",
"preserved_elements": ["{{question}}", "Q:", "A:", "\\n"],
"source_lang": "en",
"target_lang": "zh",
"format_preserved": true,
"placeholders_preserved": 1
}
}
示例 2:复杂 System Prompt 翻译 Example 2: Complex System Prompt
{
"code": 0,
"message": "success",
"data": {
"translated_prompt": "あなたは{{domain}}を専門とする{{role}}です。以下のルールに従ってください:\n1. <context></context>ブロックを常に参照すること\n2. キーワードには**太字**を使用すること\n3. ```json``` 形式で出力すること\n\n例:\nQ: {{term}}とは何ですか?\nA: {\"definition\": \"...\", \"source\": \"{{source}}\"}",
"preserved_elements": [
"{{role}}", "{{domain}}", "{{term}}", "{{source}}",
"<context></context>", "**太字**", "```json```",
"Q:", "A:", "1.", "2.", "3."
],
"source_lang": "en",
"target_lang": "ja",
"format_preserved": true,
"placeholders_preserved": 4
}
}
应用场景 Use Cases
场景 Scenario 最佳方案 Approach
AI 应用多语言部署
Multi-language AI deployment
将 System Prompt 翻译为多语言,通过 model_context 适配不同模型,确保指令等效
Translate system prompts to multiple languages, adapt via model_context for different models, ensuring instruction equivalence
跨语言 Prompt Engineering
Cross-lingual prompt engineering
设计师用母语编写 Prompt,翻译为目标模型语言,通过 preserve_placeholders 保持变量完整
Designers write prompts in native language, translate to target model language, keep variables intact with preserve_placeholders
Few-shot 示例翻译
Few-shot example translation
翻译 few-shot 示例时使用 prompt_type: "few_shot",保留 Q:/A: 分隔符和示例结构
Use prompt_type: "few_shot" when translating examples; preserves Q:/A: separators and example structure
Chatbot 角色本地化
Chatbot persona localization
将角色定义和对话风格翻译为本地化语言,同时关联术语库保持品牌术语一致
Translate persona definitions and conversation styles while linking glossary for brand consistency
结构化 Prompt 模板翻译
Structured prompt templates
翻译 JSON/YAML 格式的 Prompt 模板,保留 key 名不变,仅翻译 value 和 description 字段
Translate JSON/YAML prompt templates, preserving key names, translating only values and descriptions
多平台 Prompt 适配
Multi-platform prompt adaptation
同一套逻辑翻译为不同平台的 Prompt 风格,结合 model_context 自动优化格式差异
Translate the same logic to different platform prompt styles, auto-optimizing format differences via model_context
使用限制 Usage Limits
限制项 Limit Item 上限 Cap 说明 Notes
单次 Prompt 长度 Prompt length 50,000 字符 chars 超出后请分批次翻译 Split into batches if exceeded
请求频率 Rate limit 60 次/分钟 req/min 按账号计算 Per account
自定义变量数量 Custom variables 50 单个变量名最长 30 字符 Max 30 chars per variable name
自动保留元素数 Auto-preserved elements 500 超过此数量部分元素可能被忽略 Elements beyond this count may be ignored
错误码 Error Codes
HTTP Code 错误码 Error Code 说明 Description
200 0成功 Success
400 1001参数错误,请检查必填参数和参数格式 Invalid parameter; check required fields and format
400 1002不支持的语言代码 Unsupported language code
400 1007不支持的 model_context,请参考支持列表 Unsupported model_context; refer to the supported list
400 1008custom_variables 包含无效变量名 custom_variables contains invalid variable names
401 2001认证失败,Token 无效或已过期 Authentication failed; invalid or expired token
403 2003无权限访问该资源 Access denied; insufficient permissions
404 2004关联的 glossary_id 不存在 Referenced glossary_id not found
413 3001请求文本超出长度限制(最大 50,000 字符) Text exceeds maximum length (50,000 chars)
422 3006无法识别的 Prompt 格式,占位符损坏或格式标签不闭合 Unrecognizable prompt format; corrupted placeholders or unclosed format tags
429 4001请求频率超限,请稍后重试 Rate limit exceeded; please retry later
500 5001服务器内部错误,请重试或联系技术支持 Internal server error; retry or contact support
最佳实践 Best Practices
建议 Suggestion 说明 Description
明确 Prompt 类型
Specify prompt type
设置 prompt_type 帮助引擎选择最优翻译策略,system prompt 的翻译方式与 user prompt 不同
Set prompt_type to help the engine choose the best strategy; system prompts are translated differently from user prompts
声明自定义变量
Declare custom variables
将 Prompt 中需要原样保留的变量名通过 custom_variables 明确列出,增加保留的可靠性
Explicitly list variable names that must be preserved via custom_variables for added reliability
关联术语库确保一致性
Link glossary for consistency
如 Prompt 中包含产品名、行业术语,通过 glossary_id 关联术语库来保证翻译一致性
If prompts contain product names or industry terms, link a glossary via glossary_id for consistent translation
翻译后验证关键元素
Verify key elements post-translation
检查 preserved_elements 和 placeholders_preserved 字段,确认关键元素未被遗漏
Check preserved_elements and placeholders_preserved fields to confirm no critical elements were missed
分批处理冗长 Prompt
Batch long prompts
超过 10,000 字符的 Prompt 建议按文本段落拆分翻译,利用 custom_variables 跨批次保持一致
For prompts over 10,000 chars, split by paragraphs and use custom_variables to maintain consistency across batches
按目标模型优化
Optimize for target model
使用 model_context 指定目标模型,引擎会适配该模型的提示格式习惯,提升指令遵循效果
Use model_context to specify the target model; the engine adapts to its prompt format conventions for better instruction following
与其他 API 组合使用 Combination with Other APIs
组合场景 Combo Scenario 使用方式 Approach
Prompt 翻译 + 语言润色
Translate + Polish
翻译后的 Prompt 可能存在语气生硬问题,再用润色 API 以 casual 风格优化自然度
Translated prompts may sound stiff; use Polishing API with casual style to improve naturalness
Prompt 翻译 + 语法纠错
Translate + Grammar
非母语编写的源 Prompt 先用语法纠错 修正,再翻译为目标语言
Fix source prompts written by non-native speakers with Grammar Check first, then translate
Prompt 翻译 + 术语库
Translate + Glossary
通过 glossary_id 直接关联术语库 ,也可先用术语库校验再翻译
Link glossary directly via glossary_id, or validate terms first then translate
使用说明
Notes
所有 API 请求均使用 HTTPS,建议开启 HTTP Keep-Alive 以提高性能。
All API requests use HTTPS; enable HTTP Keep-Alive for better performance.
请勿在客户端代码中暴露 Access Token,建议通过后端代理调用。
Do not expose your Access Token in client-side code; use a backend proxy.
推荐设置合理的超时时间(30 秒),并实现指数退避重试策略。
Set a reasonable timeout (30s) and implement exponential backoff for retries.