# Translation

> Translate text between languages with LLM-powered translation and real-time streaming output. Send text in any language, name a target language, and read the translation as it's generated over Server-Sent Events.

## What you get

Translation streams its response through **Server-Sent Events (SSE)**, so you receive translated text while it is still being generated rather than waiting for the full result.

| Included | Typical use case |
| --- | --- |
| Real-time translation between languages | Live chat and customer support translation |
| Streaming output as content is generated | Real-time subtitles and multilingual captions |
| Source language auto-detection | Cross-language workflows in apps and internal tools |
| Flexible model and prompt configuration | Tuning translation behavior per product surface |

The flow is three steps: send the source text and target language, receive streaming chunks while the translation is generated, then wait for the `complete` event to get the final translation.

## Endpoint

`POST /api/v1/translation/stream`

Unlike most Munsit endpoints, this one authenticates with **either an API key or a JWT token** in the `Authorization: Bearer` header.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `text` | string | **Yes** | Input text to translate. |
| `target_language` | string | **Yes** | Full target language name, such as `Arabic`. |
| `source_language` | string | No | Source language, or `string` for auto-detection. |
| `model_name` | string | No | Translation model, default `qwen/qwen3-32b`. |
| `prompt_name` | string | No | Prompt template, default `quick-translate`. |
| `prompt_version` | string | No | Prompt version, default `1.2.0`. |

## Translate with streaming

Keep the connection open and read events until `complete` arrives.

```bash
curl -N -X POST "https://api.munsit.com/api/v1/translation/stream" \
  -H "Authorization: Bearer YOUR_MUNSIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Welcome to Munsit",
    "target_language": "Arabic"
  }'
```

```python
import requests

response = requests.post(
    "https://api.munsit.com/api/v1/translation/stream",
    headers={"Authorization": "Bearer YOUR_MUNSIT_API_KEY"},
    json={"text": "Welcome to Munsit", "target_language": "Arabic"},
    stream=True,
)

# read Server-Sent Events until the `complete` event arrives
for line in response.iter_lines(decode_unicode=True):
    if line:
        print(line)
```

```javascript
const response = await fetch('https://api.munsit.com/api/v1/translation/stream', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_MUNSIT_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ text: 'Welcome to Munsit', target_language: 'Arabic' }),
});

// read Server-Sent Events until the `complete` event arrives
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  process.stdout.write(decoder.decode(value));
}
```

```go
package main

import (
    "bufio"
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
    "os"
)

func main() {
    body, _ := json.Marshal(map[string]string{
        "text":            "Welcome to Munsit",
        "target_language": "Arabic",
    })

    req, _ := http.NewRequest("POST", "https://api.munsit.com/api/v1/translation/stream", bytes.NewReader(body))
    req.Header.Set("Authorization", "Bearer "+os.Getenv("MUNSIT_API_KEY"))
    req.Header.Set("Content-Type", "application/json")

    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()

    // read Server-Sent Events until the `complete` event arrives
    scanner := bufio.NewScanner(resp.Body)
    for scanner.Scan() {
        line := scanner.Text()
        if line != "" {
            fmt.Println(line)
        }
    }
}
```

## Stream events

Four event types arrive over the SSE connection, in order.

| Event | What it carries |
| --- | --- |
| `session_info` | Request and session metadata. |
| `start` | Translation start, with the detected source language. |
| `chunk` | Partial translation content — append as it arrives. |
| `complete` | Final translation output and metadata. |

> Keep the connection open. The response is streamed as Server-Sent Events — don't close until you've received a complete event, or you'll miss the final translation output.

## Go further

Translation slots into any transcript pipeline.

- [Transcribe audio](/speech-to-text/transcribe) — Produce Arabic transcripts to translate. — `POST /speech-to-text`

- [Sentiment analysis](/understanding/sentiment-analysis) — Score tone and emotion on the same transcript. — `POST …/sentiment-analysis`

- [Keyword extraction](/understanding/keyword-extraction) — Pull entities and themes from meeting transcripts. — `POST …/keyword-extraction`

- [Authentication](/authentication) — API keys, JWT tokens, and where each is accepted. — `guide`
