Additional capabilities
Translate text
The Translation API translates text from one language to another. While Palmyra X models can perform translation tasks, they are not optimized for these tasks and may not perform well without correct prompting. Palmyra Translate is a dedicated model optimized for translation use cases.
You need an API key to access the Writer API. Get an API key by following the steps in the API quickstart.
We recommend setting the API key as an environment variable in a .env
file with the name WRITER_API_KEY
.
Translation endpoint
Endpoint: POST /v1/translation
Request body
The request body is a JSON object with the following fields. All fields are required.
Parameter | Type | Description |
---|---|---|
model | string | The model to use for the translation. Must be palmyra-translate . |
source_language_code | string | The ISO-639-1 language code of the original text to translate. For example, en for English, zh for Chinese, fr for French, es for Spanish. If the language has a variant, the code appends the two-digit ISO-3166 country code. For example, Mexican Spanish is es-MX . See the list of supported languages and language codes. |
target_language_code | string | The ISO-639-1 language code of the target language. For example, en for English, zh for Chinese, fr for French, es for Spanish. If the language has a variant, the code appends the two-digit ISO-3166 country code. For example, Mexican Spanish is es-MX . See the list of supported languages and language codes. |
text | string | The text to translate. |
formality | Boolean | If the target language supports formal or informal language, this parameter controls whether to use formal (true ) or informal language (false ). See which languages support formality. |
length_control | Boolean | If the target language supports length control, this parameter controls whether to control the length of the translation. See which languages support length control. |
mask_profanity | Boolean | If the target language supports profanity masking, this parameter controls whether to mask profane words. See which languages support profanity masking. |
Response format
The response is a JSON object with a data
field that contains the translated text as a string.