Paxa Labs

แปลข้อความ

POSThttps://api.paxalabs.com/v1/translateเปิดใน Playground

POST /v1/translate แปลข้อความจากทุกภาษาเป็นไทย หนึ่งคำแปลต่อหนึ่งท่อนข้อความ คิดเครดิตตามตัวอักษรก่อนประมวลผล และคืนให้เมื่อล้มเหลว

ดูเป็น Markdown
curl -X POST https://api.paxalabs.com/v1/translate \
  -H "Authorization: Bearer $PAXA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Welcome to our store. Free shipping on orders over 500 baht.",
    "model": "paxa-translation-lite-v1",
    "source": "en",
    "formality": "formal",
    "borrowed_words": "auto",
    "context": "Homepage banner for an online fashion store.",
    "glossary": [{"source": "free shipping", "target": "ส่งฟรี"}]
  }'
{
  "translations": [
    {
      "text": "ยินดีต้อนรับสู่ร้านของเรา ส่งฟรีเมื่อสั่งซื้อครบ 500 บาท",
      "detected_source": "en"
    }
  ],
  "usage": {
    "text_chars": 60,
    "reference_chars": 0,
    "billable_chars": 60,
    "credits": 2,
    "glossary_terms_sent": 0,
    "glossary_terms_available": 0
  }
}

ส่ง text เป็นข้อความเดี่ยวหรืออาร์เรย์ของหลายท่อน การควบคุมระดับภาษา คำทับศัพท์ อภิธานศัพท์ และตัวอย่างสไตล์อยู่ในคู่มือการแปลภาษา

เฮดเดอร์#

authorizationBearer pxa_...จำเป็น

Authorization: Bearer pxa_... (recommended).

x-api-keypxa_...

Alternative to the Authorization header. Ignored when Authorization is present.

idempotency-keystring

Makes a retry safe: two requests carrying the same key are charged once. One request per key runs at a time. A concurrent duplicate answers 409 idempotency_in_flight. Reuse a key only to retry an identical request. A changed payload is rejected with 422. Accepts up to 200 printable ASCII characters other than space.

1 to 200 characterspattern ^[!-~]+$

การยืนยันตัวตน

เนื้อหา#

textstring or object or array of string or objectsจำเป็น

The text to translate: one string, or an array of up to 200 segments translated together (one request, one charge, shared document context; segment boundaries are preserved in the response). Translated characters cost 25 credits per 1000. Reference characters, meaning instructions, context, examples, do_not_translate strings, and glossary, cost 8 credits per 1000 because the model reads them without translating them. Both are billed per character, summed, and rounded up once to the next hundredth of a credit, minimum 2 credits per request. This field accepts at most 20,000 characters, counted once per requested rendering, because each rendering produces that much Thai. The whole request accepts at most 200,000 billable characters. The response reports the exact split in usage.

ตัวอย่าง "The quick brown fox jumps over the lazy dog."
modelstringจำเป็น

Translation model id, for example paxa-translation-lite-v1. GET /v1/models lists the served catalog.

1 to 100 charactersตัวอย่าง "paxa-translation-lite-v1"
sourcestring

Source language as an ISO 639-1 code, or "auto" (the default) to detect it per segment. Codes accepted as explicit pins today: en, zh, ja, ko, ar, fr, de, hi, id, ms, pt, ru, es, vi. Auto-detection accepts any input language, including mixed-language text.

ค่าเริ่มต้น "auto"up to 16 characters
target"th"

Target language. Thai is the only target served today; the field exists so more targets can arrive without a breaking change.

ค่าเริ่มต้น "th"
formality"auto" or "formal" or "casual"

Thai register: "formal" produces polite written Thai (polite particles where natural, formal vocabulary), "casual" produces conversational Thai, and "auto" (the default) matches the tone of the source.

ค่าเริ่มต้น "auto"
borrowed_words"auto" or "transliterate" or "preserve"

How to handle borrowed words. "auto", the default, uses the established Thai form where one exists. "transliterate" renders borrowed words in Thai script. "preserve" keeps technical terms and proper nouns in their original script.

ค่าเริ่มต้น "auto"
format"text" or "markdown" or "html"

What the segments are written in. "text" (the default) treats them as prose. "markdown" and "html" translate only the human-readable prose. Link targets, code, tags, and attributes come back untouched. Thai is written without spaces between words. An inline tag moved by one character therefore changes where a word breaks, which is why these modes exist.

ค่าเริ่มต้น "text"
alternativesinteger

How many distinct renderings to return per segment, best first. Above 1 the extras arrive in the alternatives array of each result. Each rendering is a full pass over the text. The text rate therefore multiplies by this number, and so does the text ceiling: asking for 5 renderings leaves a 5th of the character allowance for the text itself. Reference material is read once and charged once. At most 5.

ค่าเริ่มต้น 1min 1max 5
do_not_translatearray of strings

Strings that must appear in the translation exactly as written: product names, code identifiers, citations. Applied on top of borrowed_words, which decides everything else.

instructionsstring

Free-form direction for the translator, covering tone, register, terminology, house rules, and anything the fixed options cannot express. Applied to every segment. Its characters bill at the reference rate. At most 4,000 characters. Instructions govern style only. They cannot change the response shape. They cannot make the model act on the text it is translating either.

1 to 4,000 charactersตัวอย่าง "Write for a hotel front desk. Keep room names in English."
contextstring

Background that conditions the translation without being translated: the surrounding document, the domain, or the intended audience. Its characters bill at the reference rate. At most 100,000 characters.

1 to 100,000 characters
examplesarray of objects

Style examples the translation imitates in tone, register, and phrasing. Accepts up to 100 source and target pairs. Both sides of every pair bill at the reference rate.

ดูฟิลด์ย่อย
examples[].sourcestringจำเป็น

A source sentence in the style to follow.

1 to 2,000 characters
examples[].targetstringจำเป็น

Its preferred Thai translation.

1 to 2,000 characters
glossaryarray of objects

Terminology the translation must use. Accepts up to 5,000 term pairs. The model applies each term contextually, inflecting, casing, and placing it grammatically. Send a whole glossary. Terms whose source does not appear in the text are dropped before the request runs. Dropped terms are neither sent to the model nor billed. Matching ignores case, accents, and typographic apostrophes. It sees through suffixes and German compounds. It needs no word boundaries, and works in Chinese, Japanese, and Thai. Both sides of every surviving pair bill at the reference rate. The response reports how many were sent.

ดูฟิลด์ย่อย
glossary[].sourcestringจำเป็น

The term as it appears in the source text.

1 to 200 characters
glossary[].targetstringจำเป็น

The Thai rendering to use for it.

1 to 200 characters
glossary[].alwaysboolean

Send this term even when it does not appear in the text. Use it for a term that governs a concept, such as an abbreviation the text spells out. Use it also when inflection changes the stem of the word, as an irregular plural or a Russian case ending does.

ค่าเริ่มต้น false
glossary_mode"matched" or "all"

How to handle the glossary. "matched", the default, sends and bills only the terms whose source appears in the text. "all" sends and bills every term you attach, for callers who would rather pay than reason about matching.

ค่าเริ่มต้น "matched"

การตอบกลับ#

The translated text.

translationsarray of objectsจำเป็น

One entry per input segment in input order; exactly one entry when text was a single string.

ดูฟิลด์ย่อย
translations[].idstring

The id you gave this segment, echoed back. Absent when the segment was sent as a bare string.

translations[].textstringจำเป็น

The Thai translation of this segment.

translations[].detected_sourcestringจำเป็น

The detected (or explicitly pinned) source language of this segment as an ISO 639-1 code; "und" when detection is inconclusive.

translations[].alternativesarray of strings

Further renderings of this segment, best first, when alternatives was above 1. The primary rendering stays in text and is not repeated here.

translations[].reviewobject

Present only when a delivered translation is worth checking. These are our own checks on the result. They never fail or refuse a request, and the translation is delivered and charged either way. A response whose segments carry no review member passed every check.

ดูฟิลด์ย่อย
translations[].review.reasonstringจำเป็น

Why this segment is worth a look. `empty`, the model returned nothing. `untranslated`, the output matches the input. `glossary_term_missing`, a term you sent does not appear. `preserved_span_missing`, a do_not_translate string is absent. `too_long`, the result exceeds max_length. `markup_changed`, the markup structure differs.

translations[].review.detailstring

The specific term, span, or measurement behind the reason, when there is one.

usageobjectจำเป็น

What the request was billed for.

ดูฟิลด์ย่อย
usage.text_charsintegerจำเป็น

Characters of text, summed across segments.

usage.reference_charsintegerจำเป็น

Characters the model read without translating: instructions, context, examples, do_not_translate strings, and the glossary terms actually sent.

usage.billable_charsintegerจำเป็น

text_chars plus reference_chars.

usage.creditsnumberจำเป็น

What this delivery cost, in credits, exact to a hundredth. An idempotent replay reports the ORIGINAL request's charge, since that one charge is what paid for this delivery too; your balance moves only once.

usage.glossary_terms_sentintegerจำเป็น

Glossary terms that reached the model and were billed for.

usage.glossary_terms_availableintegerจำเป็น

Glossary terms attached to the request. The gap between this and glossary_terms_sent is what pruning dropped.

ข้อผิดพลาด#

400validationThe request body, query, or headers failed validation against the endpoint schema, or broke a rule the endpoint's reference states. A field the schema refused adds two fields to the problem body. path names the first failing field by location and name in dot form, such as body.voice or headers.idempotency-key. A body that could not be read gives the path body alone. reason is one stable code from the validation reasons list.
400unknown_modelThe model field does not name a served model.
400unsupported_languageThe source field names a language the model does not accept as an explicit pin.
400text_too_longThe text exceeds the model's per-request character ceiling.
400request_too_largeThe request's billable characters exceed the model's total ceiling. Translation bills every field: instructions, context, examples, do_not_translate strings, and the glossary count toward the ceiling alongside the text.
401unauthorizedThe request carried no API key, or the key is invalid or disabled.
402insufficient_creditsThe account does not have enough credits for this request. Nothing was charged.
403key_limitThis API key reached its spending cap. Nothing was charged.
409idempotency_in_flightAnother request with this Idempotency-Key is in flight right now.
409idempotency_refundedThe original request under this Idempotency-Key failed and was refunded.
422idempotency_mismatchThis Idempotency-Key was already used for a different request.
422content_blockedThe upstream safety system declined to process this content. The charge was refunded.
429rate_limitedRequests per minute for the plan are exhausted. One window covers the whole account, across every product and every key.
429concurrency_limitedThe account holds the plan's full count of concurrent requests for this product. Nothing was charged. Each product is limited separately, and an open live connection holds one slot of its product for its lifetime.
500internalRequest state was inconsistent on the server.
502provider_errorModel inference failed after the request was charged.
503provider_unavailableThe model behind this endpoint is not available right now. Nothing was charged.