POST
/
translation
/
stream
curl --request POST \
  --url https://client.camb.ai/apis/translation/stream \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '{
  "text": "<string>",
  "source_language": 1,
  "target_language": 1
}'
"<string>"

This endpoint provides instantaneous text translation with adaptive context handling, streaming results character-by-character as they’re processed. This approach enables real-time subtitling, live chat translation, and dynamic content localization without waiting for full document processing.

Customizing Your translation

Contextual Adaptation Parameters

Enhance your translations with linguistic context controls:

  • Formality Level (Optional):

    SettingValueUse Case
    Formal1Business documents, academic papers, official correspondence
    Casual2Chat messages, social media, casual communication
  • Grammatical Gender (Optional):

    Applies to languages with gender-specific grammar

    SettingValue
    Not Specified0
    Male1
    Female2
    Neutral9

Language Support

Implementation Guide

Streaming Translation Workflow:

import requests

translation_config = {
    "text": "Jupiter, the largest planet in our solar system...",
    "source_language": 1,   # English
    "target_language": 81,  # Hindi
    "formality": 2,         # Formal
    "gender": 1             # Male grammatical gender
}

def sync_translation_stream(config):
    """Handle translation stream synchronously"""
    headers = {"x-api-key": "your_api_key_here"}

    with requests.post(
        "https://client.camb.ai/apis/translation/stream",
        json=config,
        headers=headers,
        stream=True
    ) as response:

        # Verify successful connection
        response.raise_for_status()

        # Display credit cost
        print(f"Credits required: {response.headers.get('X-Credits-Required', 'Unknown')}")

        # Process stream chunks
        full_translation = ""
        for chunk in response.iter_content(chunk_size=128):
            try:
                decoded = chunk.decode('utf-8')
                full_translation += decoded
                print(decoded, end='', flush=True)
            except UnicodeDecodeError:
                print("�", end='')  # Error placeholder

        return full_translation

# Execute the translation
translated_text = sync_translation_stream(translation_config)
print("\nComplete Translation:\n", translated_text)

When to use synchronous vs asynchronous:

  • Use synchronous (requests) for:

    • Simple scripts
    • Low-concurrency applications
    • Quick prototyping
  • Use asynchronous (aiohttp) for:

    • High-performance applications
    • Parallel translation streams
    • Web servers with async frameworks

Response Handling

  • Stream Format: UTF-8 encoded text/event-stream with incremental translations.

  • Credit Tracking: X-Credits-Required header shows computational resources used.

  • Error Handling: Failed streams immediately terminate with error message.

Use Case Examples

  • Live Caption Translation: Convert spoken language subtitles in real-time

  • Chat Localization: Instant message translation for multilingual support teams

  • Document Preview: Stream translated content while full processing continues

This streaming solution is ideal for applications requiring immediate partial results while maintaining full translation context awareness. The character-level streaming allows for dynamic UI updates and progressive content rendering.

Authorizations

x-api-key
string
header
required

The x-api-key is a custom header required for authenticating requests to our API. Include this header in your request with the appropriate API key value to securely access our endpoints. You can find your API key(s) in the 'API' section of our studio website.

Body

application/json

Response

200
text/event-stream

Text translation stream

The response is of type string.