Connect your AI

Unlock AI-powered diplomacy, dynamically generated historical events, and a strategic advisor by connecting any AI provider — from free local models to premium cloud APIs.

What AI Powers in Open Historia

AI Diplomacy — negotiate with any nation via natural language chat
AI Intelligence Briefings — get summaries of any country's status
AI-Generated Events — dynamic events shaped by your decisions and the world state
AI Advisor — consult for strategic guidance, economic analysis, and war planning
AI Combat Resolution — battles resolved by the AI based on troop strength, terrain, and strategy

How It Works

Open Historia supports five types of AI providers from a single settings panel. You can switch between them at any time:

For providers that don't send CORS headers from the browser (OpenAI, OpenAI Compatible, Anthropic Compatible), the game's Express server includes a /api/ai/relay endpoint that proxies requests securely. Gemini and Anthropic's native APIs support direct browser access and don't use the relay.

Provider Setup Options

Google Gemini (Free Tier Available)

Gemini is the default provider and the easiest way to get started. Google offers a free tier on Google AI Studio that's more than enough for solo play.

Get an API key

Go to Google AI Studio, sign in with a Google account, and click "Create API Key." It's free — no billing setup required.

Set the model

The default gemini-2.5-flash-lite works great out of the box. You can switch to gemini-2.5-flash or gemini-2.5-pro for stronger reasoning (check rate limits on the free tier).

Configure in Open Historia

In the game's settings, select Gemini as the provider and paste your API key. No endpoint URL needed.

OpenAI (GPT-4o, GPT-4.1, o-series)

Use OpenAI's official API for GPT-4o, GPT-4.1, or o-series reasoning models. Requires a paid API account with pre-loaded credits.

Get an API key

Sign up at platform.openai.com, add a payment method, and create an API key under "API Keys."

Choose a model

gpt-4.1-mini is fast and inexpensive, gpt-4.1 handles complex diplomacy, and o4-mini excels at strategic reasoning.

Configure in Open Historia

Select OpenAI as the provider, paste your API key, and optionally specify a model. The endpoint is pre-configured.

Anthropic Claude

Use Anthropic's Claude via the Messages API. Known for nuanced writing and strong instruction-following — excellent for immersive diplomacy and rich event generation.

Get an API key

Sign up at console.anthropic.com and generate an API key.

Choose a model

claude-sonnet-4-20250514 offers the best balance of quality and speed. claude-haiku-3-5-20241022 is faster and cheaper.

Configure in Open Historia

Select Anthropic as the provider and paste your API key. Direct browser access — no relay needed.

DeepSeek

DeepSeek offers powerful models at very low cost. Their API is OpenAI-compatible, so it works through the "OpenAI Compatible" provider option.

Get an API key

Register at platform.deepseek.com, top up credits (minimum $2), and create an API key.

Set the endpoint

DeepSeek's API base URL is https://api.deepseek.com/v1. The model deepseek-chat covers most needs; deepseek-reasoner is available for complex strategic reasoning.

Configure in Open Historia

Select OpenAI Compatible as the provider. Set the endpoint to https://api.deepseek.com/v1, enter your API key, and set the model to deepseek-chat.

Local LLMs (Free & Private)

Run models entirely on your own hardware. No API keys, no internet required after download, completely private. Use the OpenAI Compatible provider in settings.

Ollama (Recommended for Easiest Setup)

Ollama is the simplest way to run LLMs locally. Works on Windows, macOS, and Linux.

Install Ollama

Download from ollama.com and install.

Pull a model

ollama pull llama3.2 — or any model you prefer. Recommended: llama3.2 (lightweight), mistral (balanced), qwen2.5 (strong reasoning).

Configure in Open Historia

Select OpenAI Compatible, set the endpoint to http://localhost:11434/v1. No API key needed for local use.

LM Studio (GUI-Focused)

LM Studio provides a graphical interface for downloading and running models. Great for Windows and macOS users who prefer a GUI.

Install LM Studio

Download from lmstudio.ai.

Download a model

Use the built-in model browser to search and download a model (e.g., Llama 3.2, Mistral 7B, Phi-3).

Start the local server

Go to the "Local Server" tab, load your model, and click "Start Server." The default URL is http://localhost:1234/v1.

Configure in Open Historia

Select OpenAI Compatible, set the endpoint to http://localhost:1234/v1. No API key needed.

llama.cpp (Maximum Performance)

llama.cpp is the most performant option for technical users. Runs GGUF-format models with minimal overhead.

Build llama.cpp server

Follow the build instructions for your platform.

Download a GGUF model

Get a GGUF model from Hugging Face (e.g., Llama-3.2-3B-Instruct-Q4_K_M.gguf).

Start the server

./llama-server -m model.gguf --port 8080

Configure in Open Historia

Select OpenAI Compatible, set the endpoint to http://localhost:8080/v1.

Other Cloud APIs (OpenAI-Compatible)

Any cloud service that speaks the OpenAI chat completions protocol works through the OpenAI Compatible provider. Popular options:

Service Endpoint URL Notable
Groq https://api.groq.com/openai/v1 Fast inference, generous free tier
Together.ai https://api.together.xyz/v1 Wide model selection, $1 free credit
OpenRouter https://openrouter.ai/api/v1 Access 300+ models through one API
DeepInfra https://api.deepinfra.com/v1/openai Open-source models, pay-per-token
Fireworks https://api.fireworks.ai/inference/v1 Fast, serverless GPU inference

For any of these, select OpenAI Compatible, paste the endpoint URL and your API key from that service, and set the model name. The relay handles CORS automatically.

Choosing the Right Option

Provider Cost Quality Privacy Best For
Gemini Free tier available Excellent Cloud Quickest setup, casual play
OpenAI Pay-per-token Excellent Cloud Best quality, heavy use
Anthropic Claude Pay-per-token Excellent Cloud Rich narrative, diplomacy
DeepSeek Very low cost Very good Cloud (China) Budget-friendly quality
Ollama / LM Studio / llama.cpp Free Varies by model Fully local Privacy, offline play
Groq / Together / OpenRouter Free tier / low cost Very good Cloud Fast cloud inference, many models

Model Recommendations

Model Provider Best For Notes
Gemini 2.5 Flash Google (native) All features, great free tier Default — excellent all-rounder
Gemini 2.5 Flash Lite Google (native) Budget / free tier Fast, generous rate limits
GPT-4.1 Mini OpenAI (native) Fast, inexpensive Good for diplomacy and events
GPT-4.1 OpenAI (native) Complex strategy & narrative Top-tier quality, higher cost
o4-mini OpenAI (native) Strategic reasoning Reasoning model, excels at planning
Claude Sonnet 4 Anthropic (native) Nuanced diplomacy, rich narrative Best writing quality
DeepSeek-Chat (V3) DeepSeek (compatible) Budget-friendly quality Very low cost per token
Llama 3.2 3B Local (Ollama / LM Studio) Diplomacy chat, advisor ~4 GB RAM needed
Mistral 7B Local (Ollama / LM Studio) Events, diplomacy, advisor ~8 GB RAM needed
Qwen 2.5 7B Local (Ollama / LM Studio) Strong reasoning, all features ~8 GB RAM needed

For local models: smaller models respond faster and use less RAM. Larger models generate richer events and better strategic advice. For cloud models: Gemini's free tier is the best starting point; DeepSeek offers the best quality-per-dollar.

Troubleshooting

AI features are greyed out or unresponsive

Make sure your provider is configured correctly. For cloud APIs, verify your API key is valid and has credits. For local backends, check that the server is running and the endpoint URL matches. The game checks connectivity on load — if the backend isn't reachable, AI features won't activate.

API key not working

Double-check you've selected the correct provider in settings. A Gemini key won't work with the OpenAI provider, and vice versa. For OpenAI Compatible providers, ensure the endpoint URL includes the full base path (e.g., https://api.deepseek.com/v1, not just https://api.deepseek.com).

AI responses are slow

For local models: try a smaller model (3B parameters) or enable GPU acceleration. Ollama and LM Studio both support GPU offloading. For cloud APIs: slower models like GPT-4.1 or Claude Sonnet produce higher quality but take longer — try a faster model if latency is an issue. Groq is particularly fast for cloud inference.

CORS errors when using a remote backend

The game handles CORS automatically for OpenAI, OpenAI Compatible, and Anthropic Compatible providers via the relay endpoint. If you're seeing CORS errors, make sure you're using the correct provider type — Gemini and Anthropic work direct from the browser, everything else routes through /api/ai/relay.

DeepSeek / OpenRouter returns errors

These services use the OpenAI Compatible provider. Ensure the endpoint URL is correct and includes /v1. The model name must match exactly what the service expects (e.g., deepseek-chat for DeepSeek, or the full OpenRouter model slug like openai/gpt-4.1).

Related Guides

Play Open Historia