Skip to main content
Machine Translation converts text from one language to another using Spitch’s language models, which are tuned for a wide range of languages.

Request

The translate() function converts text from one supported language to another. Pass text and target. The source language is optional: leave it out and Spitch detects the input language for you, or set it when you want to specify the input language explicitly.

Parameters

ParameterTypeRequiredDescription
textstringYesThe text to translate.
targetstringYesLanguage code of the desired output (e.g. "ha").
sourcestringNoLanguage code of the input text (e.g. "en").
tonestringNoOne of neutral, warm, professional, or narration.
formalitystringNoOne of casual or formal.
Context matters. Translations can vary depending on phrasing, tone, and domain, so test with representative samples from your use case.
from spitch import Spitch

client = Spitch(api_key="YOUR_API_KEY")

translation = client.text.translate(
    text="Hey my dear friend, how are you doing?",
    source="en",
    target="ha",
    tone="warm",
    formality="casual",
)

print(translation.text)

Response

A successful request returns a JSON object with the translated text.
{
  "request_id": "86095cea-77d5-45ba-a093-0f800ac2c7df",
  "text": "Hey abokina, yaya kake?"
}
FieldTypeDescription
request_idstringRequest identifier for support and audit flows.
textstringThe translated output.
For error codes and retry guidance, see Troubleshooting.