Skip to main content
All use casesUse Case

Build a multilingual AI backend that serves global users.

Detect input language, route to appropriate LLM context, maintain per-language conversation history, and return localized AI responses — all with the kit's pre-built infrastructure.

FastAPIOpenAIAnthropicPostgreSQLRedis

The usual pain points

  • Detecting and handling multiple languages in LLM prompts
  • Maintaining separate conversation contexts per locale
  • Routing to different models or prompts based on language
  • Tracking costs across different language usage patterns

How the kit solves them

  • LLM abstraction layer accepts locale-tagged requests for routing
  • Session model supports per-locale conversation storage
  • System prompt templates with language-specific instructions
  • Per-request token tracking regardless of language or model

Example implementation

main.py
@router.post("/v1/support/multilingual-chat")
async def multilingual_chat(
    body: MultilingualChatRequest,
    key: APIKey = Depends(get_api_key),
):
    locale = body.locale or detect_language(body.message)
    system_prompt = SYSTEM_PROMPTS.get(locale, SYSTEM_PROMPTS["en"])
    history = await session_store.get(body.session_id, locale=locale)

    response = await llm.chat(
        messages=[*history, {"role": "user", "content": body.message}],
        system=system_prompt,
        track_tokens=True,
    )
    await meter.record(key.id, response.tokens)
    return {"reply": response.content, "locale": locale}

Ready to build your multilingual ai api backend?

FastAPI AI Kit ships with everything shown above, pre-configured and production-ready. Clone the repo and start building in minutes.

Ready to ship your AI backend this weekend?

Join developers who skipped weeks of boilerplate and went straight to building.

Read the docs
No subscriptions · One-time payment · Lifetime updates