> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# 翻訳を作成

> テキストを対象言語に翻訳します

## 概要

`/v1/translations` は**テキストからテキストへの翻訳**に使用します。

<Note>
  この endpoint は [音声翻訳](/ja/api-reference/audio/create-translation) とは異なります。音声ファイルを受け取り、常に英語テキストを出力します。
</Note>

agent workflow では、まず現在の推奨翻訳 model を確認してください。

```bash theme={null}
curl "https://api.tokenlab.sh/v1/models?recommended_for=translation" \
  -H "Authorization: Bearer sk-your-api-key"
```

そのうえで、選択した model を `/v1/translations` に明示的に送信します。

<Note>
  `recommended_for=translation` は**テキスト翻訳**（`POST /v1/translations`）にのみ適用され、[音声翻訳](/ja/api-reference/audio/create-translation) には適用されません。
</Note>

## リクエストボディ

<ParamField body="model" type="string" required>
  `/v1/models?recommended_for=translation` が返す翻訳 model ID。
</ParamField>

<ParamField body="text" type="string" required>
  翻訳する元のテキスト。
</ParamField>

<ParamField body="target_language" type="string" required>
  対象言語コードまたは言語名。model の対応状況によって異なります。
</ParamField>

<ParamField body="source_language" type="string">
  任意の元言語ヒント。
</ParamField>

<ParamField body="mime_type" type="string" default="text/plain">
  元テキストの形式。サポート値は `text/plain` と `text/html` です。
</ParamField>

<ParamField body="user" type="string">
  abuse monitoring と request tracing のための任意の end-user 識別子。
</ParamField>

## レスポンス

<ResponseField name="text" type="string">
  翻訳後のテキスト。
</ResponseField>

<ResponseField name="model" type="string">
  翻訳を生成した model。
</ResponseField>

<ResponseField name="source_language" type="string | null">
  model が検出または受理した元言語。
</ResponseField>

<ResponseField name="target_language" type="string">
  リクエストで使用した対象言語。
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tokenlab.sh/v1/translations" \
    -H "Authorization: Bearer sk-your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "doubao-seed-translation",
      "text": "你好，欢迎使用 TokenLab。",
      "target_language": "en"
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI
  import requests

  client = OpenAI(
      api_key="sk-your-api-key",
      base_url="https://api.tokenlab.sh/v1"
  )

  response = requests.post(
      "https://api.tokenlab.sh/v1/translations",
      headers={
          "Authorization": "Bearer sk-your-api-key",
          "Content-Type": "application/json",
      },
      json={
          "model": "doubao-seed-translation",
          "text": "你好，欢迎使用 TokenLab。",
          "target_language": "en",
      },
      timeout=30,
  )

  print(response.json()["text"])
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "text": "Hello, welcome to TokenLab.",
    "model": "doubao-seed-translation",
    "source_language": "zh",
    "target_language": "en"
  }
  ```
</ResponseExample>
