---
title: "Overview"
description: "Draft translations with any AI SDK model, update existing ones minimally and check every output without a model."
canonical_url: "https://diglot.sh/machine-translation/overview"
---
# Overview

> Draft translations with any AI SDK model, update existing ones minimally and check every output without a model.

`@diglot/mt` writes the first draft of translations. It translates new segments in page-sized batches, updates an existing translation when its source changes while altering as little as possible, puts your glossary and style rules into the prompt, and runs model-free QA checks on every output. It is built on the [AI SDK](https://ai-sdk.dev), so any `LanguageModel` works.

<package-info directory="packages/mt" install="pnpm add @diglot/mt @diglot/core" name="@diglot/mt">



</package-info>

You rarely call this package directly, because the [Action](https://diglot.sh/workflow/action/overview) already uses it. Use it when you build your own pipeline or want to translate segments from a script.

## Choosing a model

Pass the `model` option as a `LanguageModel` from any AI SDK provider, or as a model id string, which is resolved through the [Vercel AI Gateway](https://vercel.com/ai-gateway). When you leave `model` out, the id is read from the `DIGLOT_MT_MODEL` environment variable, and if that isn't set either, the call throws. The gateway reads its key from `AI_GATEWAY_API_KEY`.

`gatewayModel` builds a gateway model with explicit settings:

```ts
import { gatewayModel } from '@diglot/mt'

const model = gatewayModel('anthropic/claude-sonnet-5.5', { apiKey })
```

## What is in the package

<table>
<thead>
  <tr>
    <th>
      Function
    </th>
    
    <th>
      Purpose
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a href="https://diglot.sh/machine-translation/translate-segments">
        <code>
          translateSegments
        </code>
      </a>
    </td>
    
    <td>
      Translate new segments in batches, with retries on QA errors
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://diglot.sh/machine-translation/update-translation">
        <code>
          updateTranslation
        </code>
      </a>
    </td>
    
    <td>
      Carry over or minimally update a translation after its source changed
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://diglot.sh/machine-translation/qa-checks">
        <code>
          runQa
        </code>
      </a>
    </td>
    
    <td>
      Check a translation against its source without calling a model
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://diglot.sh/machine-translation/overview#choosing-a-model">
        <code>
          gatewayModel
        </code>
      </a>
    </td>
    
    <td>
      Build a Vercel AI Gateway model
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        emptyUsage
      </code>
      
      , <code>
        addUsage
      </code>
    </td>
    
    <td>
      Create and sum <a href="https://diglot.sh/machine-translation/usage-and-cost">
        usage
      </a>
      
       records
    </td>
  </tr>
</tbody>
</table>

The prompts record a `PROMPT_VERSION`, which is stored as `promptVersion` in the `mt` block of each record so that you can tell which prompt produced a text.

## Options shared by the functions

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        locale
      </code>
    </td>
    
    <td>
      required
    </td>
    
    <td>
      The target locale, such as <code>
        fr
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        model
      </code>
    </td>
    
    <td>
      <code>
        DIGLOT_MT_MODEL
      </code>
    </td>
    
    <td>
      A model instance or a gateway model id
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        glossary
      </code>
    </td>
    
    <td>
      none
    </td>
    
    <td>
      A <a href="https://diglot.sh/machine-translation/glossary-and-style">
        glossary
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        style
      </code>
    </td>
    
    <td>
      none
    </td>
    
    <td>
      A <a href="https://diglot.sh/machine-translation/glossary-and-style">
        locale style
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subject
      </code>
    </td>
    
    <td>
      <code>
        technical documentation
      </code>
    </td>
    
    <td>
      What is being translated, used in the prompt
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sourceLocale
      </code>
    </td>
    
    <td>
      <code>
        en
      </code>
    </td>
    
    <td>
      The language of the source
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        qaRetries
      </code>
    </td>
    
    <td>
      <code>
        1
      </code>
    </td>
    
    <td>
      Retries for segments that fail an error-level QA check
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        pricing
      </code>
    </td>
    
    <td>
      none
    </td>
    
    <td>
      USD per million input and output tokens, for providers that don't report a cost
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        signal
      </code>
    </td>
    
    <td>
      none
    </td>
    
    <td>
      An <code>
        AbortSignal
      </code>
      
       that cancels requests
    </td>
  </tr>
</tbody>
</table>


## Sitemap

See the full [sitemap](https://diglot.sh/sitemap.md) for all pages.
