Skip to content

OpenAI Provider

Translify uses the official openai npm package to translate your i18n keys.

Setup

ts
// translify.config.ts
import { defineConfig } from '@ndnci/translify/config';

export default defineConfig({
  ai_translation: {
    enabled: true,
    provider: 'openai',
    openai_api_key: process.env.OPENAI_API_KEY,
    model: 'gpt-4.1-mini', // fast and affordable
    temperature: 0, // deterministic (best for translations)
    batch_size: 50, // keys per API call
  },
});

Set your API key:

bash
export OPENAI_API_KEY=sk-...

Models

ModelSpeedQualityCost
gpt-4.1-miniFastGoodLow
gpt-4.1MediumHighMedium
gpt-4oMediumHighMedium

We recommend gpt-4.1-mini for most projects.

Interpolation variables

The provider automatically preserves interpolation variables:

json
{ "greeting": "Hello, {name}!" }

Translates to French as:

json
{ "greeting": "Bonjour, {name} !" }

Rate limits and batching

batch_size controls how many keys are sent per API call (default: 50). Reduce this if you hit rate limits on your OpenAI plan.

Released under the MIT License.