-
Notifications
You must be signed in to change notification settings - Fork 8
5. AI Providers & Models
The plugin gives you a few options for the AI backend. You can swap between them based on what works best for you.
This is the default and generally the best choice for most people:
- It has a generous free tier that is more than enough for regular reading.
- Models like
gemini-3.5-flash(default primary) andgemini-3.1-flash-lite(default secondary) are extremely fast and capable. - It can handle a huge amount of context at once, which is great for long books.
- Reasoning: Gemini 2.5+ models support internal reasoning levels.
If you already use the OpenAI API, you can plug in your key here:
- You can use high-performance models like
gpt-5.5,gpt-5.4-mini, andgpt-5.4-nano. - Note:
gpt-4oandgpt-4o-miniare now considered legacy/deprecated and are available via the "Custom Model" option. - Just keep in mind that you need an API key with actual prepaid credits—a standard ChatGPT Plus subscription doesn't cover API usage.
DeepSeek offers powerful open-weight reasoning models that are very cost-effective:
- Use
deepseek-v4-flashfor standard fast requests, ordeepseek-v4-profor complex extraction. - You must create an API key at DeepSeek's platform.
Claude models are excellent for literary analysis and complex character extraction:
-
Claude 4.6 Sonnet (
claude-sonnet-4-6) and Claude 4.5 Haiku (claude-haiku-4-5) are the current supported versions. - Claude natively supports structured JSON outputs and sophisticated extended thinking.
For advanced users, you can configure up to two custom API providers (e.g., OpenRouter, openmodel.ai, LiteLLM, or self-hosted models) supporting either OpenAI or Anthropic payload formats.
-
Configurable Base URL: Set your own endpoint (e.g.,
https://openrouter.ai/api/v1/chat/completionsorhttps://api.openmodel.ai/v1/messages). -
Auto-Format Detection: The plugin automatically detects Anthropic-compatible endpoints (if the URL contains
/v1/messagesor/messages) and formats the request body and headers accordingly. You can also explicitly specify the format in the config file. - Model Selection: Manually specify any model ID supported by your provider.
- Is Reasoning Model: Toggle this if your custom model is a reasoning model (e.g., DeepSeek-R1) to allocate a larger token budget for extended thinking chains.
-
Provider-Specific Headers: Automatically includes required attribution headers (like
HTTP-RefererandX-Title) for OpenRouter, and required version/authorization headers for Anthropic-compatible endpoints.
For supported reasoning models, you can configure the "Reasoning Effort" in AI Settings to control internal 'thinking' time.
- Unset: No specific instruction sent; the model uses its internal defaults.
- Low: Fast, economical extraction for simple books.
- Medium: Balanced depth for most standard narratives.
- High: Detailed analysis for complex character webs.
Applies to: GPT-5.x (o1/o3/gpt-5), Claude (sonnet/opus/haiku), and Gemini 2.5+.
Note: DeepSeek V4 reasons inherently — this setting has no effect on it.
Sometimes API requests fail, usually because of rate limits or temporary network issues. To handle this, the plugin lets you set a primary and secondary model.
If your primary model (like claude-sonnet-4-6) fails, it'll automatically try the secondary model (like gemini-2.5-flash) before giving up.
You can manage your API keys for all providers in one place! Go to Tools Menu → X-Ray → Settings → AI Settings → API Keys & Providers.
The menu allows you to choose between:
-
Config Key: Reading directly from your
xray_config.luafile. - UI Key: A key entered directly in the KOReader interface (overrides the config file).
This allows for easy switching between different keys or testing new providers without editing files manually.
If you ever see a 429 Quota Exceeded error, it just means you've hit your provider's rate limit. Wait a minute or two and try again. If you're using Gemini's free tier, you should easily be able to process a few books a day without hitting hard caps.
For more information on the config file, see Advanced Usage.