npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

strapi-provider-translate-openrouter

v1.0.2

Published

OpenRouter LLM provider for translate plugin in Strapi 5

Readme

OpenRouter LLM provider for Strapi Translate Plugin

Translate your Strapi content using any LLM via OpenRouter or any OpenAI-compatible API (OpenAI, Ollama, LM Studio, etc.).

This provider is part of strapi-plugin-translate-llm.

Installation

npm install strapi-plugin-translate-llm strapi-provider-translate-openrouter

Configuration

Configure the provider through the plugin options in config/plugins.js:

module.exports = ({ env }) => ({
  // ...
  translate: {
    enabled: true,
    config: {
      provider: 'openrouter',
      providerOptions: {
        // Your API key - required (or set OPENROUTER_API_KEY env var)
        apiKey: env('OPENROUTER_API_KEY'),
        // Model to use (default: 'anthropic/claude-sonnet-4')
        model: 'anthropic/claude-sonnet-4',
        // Temperature: 0.1-0.3 = literal, 0.5-0.7 = creative (default: 0.3)
        temperature: 0.3,
        // Custom instructions appended to the translation prompt
        customPrompt: 'Keep "MyBrand" untranslated. Use informal register.',
        // Map Strapi locale codes to human-readable language names
        localeMap: {
          en: 'English',
          fr: 'French',
          sv: 'Swedish',
        },
        // Use a different OpenAI-compatible API (default: 'https://openrouter.ai/api/v1')
        // apiUrl: 'https://api.openai.com/v1',
      },
      translatedFieldTypes: [
        'string',
        { type: 'text', format: 'plain' },
        { type: 'richtext', format: 'html' },
        'component',
        'dynamiczone',
      ],
    },
  },
  // ...
})

Or use the default environment variables:

  • OPENROUTER_API_KEY - required, your OpenRouter API key
  • OPENROUTER_API_URL - optional, override the API endpoint

To get an API key, register at openrouter.ai/keys.

Provider Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiKey | string | OPENROUTER_API_KEY env var | Required. API key | | model | string | anthropic/claude-sonnet-4 | Any OpenRouter model | | temperature | number | 0.3 | Controls translation creativity | | customPrompt | string | — | Additional translation instructions | | localeMap | object | {} | Maps locale codes to language names | | maxTextsPerRequest | number | 20 | Max texts batched per LLM call | | maxConcurrent | number | 3 | Max parallel API requests | | apiUrl | string | https://openrouter.ai/api/v1 | API endpoint URL |

Recommended Models

| Model | Best for | Approximate cost | |-------|----------|-----------------| | anthropic/claude-sonnet-4 | Best quality/cost balance | ~$3/1M tokens | | anthropic/claude-haiku-4-5 | Fast, cheap, simple content | ~$0.80/1M tokens | | google/gemini-2.5-flash | Very cheap, fast | ~$0.15/1M tokens | | openai/gpt-4o | Strong alternative | ~$2.50/1M tokens | | openai/gpt-4o-mini | Budget option | ~$0.15/1M tokens |

Using Other OpenAI-Compatible APIs

The provider uses the OpenAI SDK internally, so it works with any compatible endpoint:

// OpenAI directly
providerOptions: {
  apiKey: env('OPENAI_API_KEY'),
  apiUrl: 'https://api.openai.com/v1',
  model: 'gpt-4o',
}

// Local Ollama
providerOptions: {
  apiKey: 'ollama',
  apiUrl: 'http://localhost:11434/v1',
  model: 'llama3',
}

Custom Prompt

The customPrompt option appends additional instructions to the system prompt. The base prompt already handles format preservation (HTML tags, Markdown syntax, JSON structure), so focus on domain-specific rules:

// Preserve brand names
customPrompt: 'Keep "UCPA" and "MyBrand" untranslated.'

// Control tone
customPrompt: 'Use informal "du" in Swedish, not "ni".'

// Combine rules
customPrompt: `
  Keep "UCPA" untranslated.
  Use informal register in all languages.
  Translate ski terminology naturally for the target audience.
`

Reliability

  • Retry with backoff — transient errors (429, 500, 502, 503) are retried up to 2 times with exponential backoff
  • Rate limiting — Bottleneck-based concurrency control prevents overwhelming the API
  • Batch fallback — if the LLM returns a malformed batch response, texts are automatically re-sent one at a time
  • HTTP keep-alive — the plugin writes periodic heartbeat bytes during slow translations, preventing reverse proxy timeouts (Heroku 30s, AWS ALB 60s)

Supported Formats

| Format | How it works | |--------|-------------| | plain | Direct text translation | | markdown | LLM preserves all Markdown syntax | | html | LLM preserves HTML tags and attributes, translates only text content | | jsonb (Blocks) | Converted to HTML before translation, converted back after |

Limitations

  • LLM translation costs vary by model and text volume — monitor usage via the admin UI or your OpenRouter dashboard
  • Translation quality depends on the chosen model; larger models produce better results for nuanced content
  • Very long texts may be split into chunks, which can occasionally affect cross-paragraph context