Translation API¶
Core translation endpoints. Translate text, detect languages, stream results, and process batches.
Endpoints¶
| Method | Endpoint | Description |
|---|---|---|
| POST | /v1/translate | Translate text |
| POST | /v1/translate/batch | Batch translate |
| POST | /v1/detect | Detect language |
| GET | /v1/languages | List languages |
| WS | /v1/stream | Real-time streaming |
POST /translate¶
Translate text from one language to another.
Request¶
curl -X POST https://api.pauhu.ai/v1/translate \
-H "Authorization: Bearer pk_..." \
-H "Content-Type: application/json" \
-d '{
"text": "The contract shall be governed by Finnish law.",
"source": "en",
"target": "fi",
"domain": "12 Law"
}'
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to translate (max 10,000 chars) |
target | string | Yes | Target language code (ISO 639-1) |
source | string | No | Source language (auto-detect if omitted) |
domain | string | No | EuroVoc domain for specialized translation |
formality | string | No | formal, informal, or neutral |
preserve_formatting | boolean | No | Preserve whitespace and formatting |
glossary_id | string | No | Use specific terminology glossary |
quality | string | No | fast, balanced, or quality |
Response¶
{
"data": {
"translation": "Sopimukseen sovelletaan Suomen lakia.",
"source_language": "en",
"target_language": "fi",
"detected_language": "en",
"confidence": 0.98,
"domain": "12 Law",
"word_count": 8,
"character_count": 46
},
"meta": {
"request_id": "req_abc123",
"processing_time_ms": 45,
"model": "pauhu-legal-v3",
"cached": false
}
}
Python SDK¶
from pauhu import Pauhu
client = Pauhu()
result = client.translate(
text="The contract shall be governed by Finnish law.",
target="fi",
domain="12 Law"
)
print(result.translation)
# "Sopimukseen sovelletaan Suomen lakia."
POST /translate/batch¶
Translate multiple texts in a single request.
Request¶
curl -X POST https://api.pauhu.ai/v1/translate/batch \
-H "Authorization: Bearer pk_..." \
-H "Content-Type: application/json" \
-d '{
"texts": [
"Hello",
"How are you?",
"Goodbye"
],
"target": "fi"
}'
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
texts | array | Yes | Array of texts (max 100 items) |
target | string | Yes | Target language code |
source | string | No | Source language |
parallel | boolean | No | Process in parallel (default: true) |
Response¶
{
"data": {
"translations": [
{
"text": "Hello",
"translation": "Hei",
"source_language": "en"
},
{
"text": "How are you?",
"translation": "Mitä kuuluu?",
"source_language": "en"
},
{
"text": "Goodbye",
"translation": "Näkemiin",
"source_language": "en"
}
],
"total_word_count": 5,
"total_character_count": 25
},
"meta": {
"request_id": "req_abc123",
"processing_time_ms": 120
}
}
Python SDK¶
results = client.translate_batch(
texts=["Hello", "How are you?", "Goodbye"],
target="fi"
)
for r in results:
print(f"{r.text} -> {r.translation}")
POST /detect¶
Detect the language of text.
Request¶
curl -X POST https://api.pauhu.ai/v1/detect \
-H "Authorization: Bearer pk_..." \
-H "Content-Type: application/json" \
-d '{
"text": "Hyvää päivää!"
}'
Response¶
{
"data": {
"language": "fi",
"language_name": "Finnish",
"confidence": 0.997,
"script": "Latin",
"alternatives": [
{"language": "et", "confidence": 0.002},
{"language": "hu", "confidence": 0.001}
]
},
"meta": {
"request_id": "req_abc123",
"processing_time_ms": 5
}
}
GET /languages¶
List all supported languages.
Request¶
Response¶
{
"data": {
"languages": [
{
"code": "fi",
"name": "Finnish",
"native_name": "Suomi",
"script": "Latin",
"supports_formality": true,
"supported_directions": ["to", "from"]
},
{
"code": "en",
"name": "English",
"native_name": "English",
"script": "Latin",
"supports_formality": false,
"supported_directions": ["to", "from"]
}
],
"total": 176
}
}
WebSocket /stream¶
Real-time streaming translation.
Connection¶
const ws = new WebSocket('wss://api.pauhu.ai/v1/stream');
// Authenticate
ws.onopen = () => {
ws.send(JSON.stringify({
type: 'auth',
api_key: 'pk_...'
}));
};
// Send translation request
ws.send(JSON.stringify({
type: 'translate',
text: 'Hello, world!',
target: 'fi',
stream: true
}));
// Receive streaming response
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'token') {
process.stdout.write(data.token);
}
if (data.type === 'complete') {
console.log('\nDone!');
}
};
Python SDK¶
# Streaming with iterator
for token in client.translate_stream(
text="Hello, world!",
target="fi"
):
print(token, end="", flush=True)
Error Codes¶
| Code | Status | Description |
|---|---|---|
invalid_request | 400 | Malformed request |
invalid_language | 400 | Unsupported language code |
text_too_long | 400 | Text exceeds 10,000 characters |
rate_limit_exceeded | 429 | Too many requests |
insufficient_quota | 402 | Character quota exhausted |
internal_error | 500 | Server error |
Rate Limits¶
| Tier | Requests/min | Characters/day |
|---|---|---|
| Pauhu® | 60 | 100,000 |
| Pro | 600 | 10,000,000 |
| Max | 3,000 | Unlimited |