Anki add-on: AI Vocab Card Generator

THIS ADDON IS ONLY FOR PEOPLE THAT KNOW EXACTLY WHAT THEY ARE DOING AI Vocab Card Generator An Anki add-on that automatically generates vocabulary card fields using AI/LLM APIs. Overview This add-on streamlines the process of creating vocabulary cards by integrating AI-powered field generation directly into Anki's card editor. Instead of manually filling out multiple fields for each card, you can generate them automatically from a single subtitle or sentence. Installation Navigate to your Anki add-ons folder: Open Anki Go to Tools → Add-ons → View Files Create a new folder named ai_vocab_generator Save the add-on code as __init__.py in this folder Create a config.json file in the same folder with the following content: { "api_endpoint": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent", "api_key": "", "model": "gemini-2.0-flash-exp", "prompt_template": "Please create a vocabulary card for the following subtitle line.\nReturn ONLY a JSON object with these exact keys:\n\nSubtitle: {{subtitle}}\nContext Before: {{contextBefore}}\nContext After: {{contextAfter}}\nSource: {{source}}\n\nReturn JSON format:\n{\n \"expression\": \"the main word or phrase to learn\",\n \"reading\": \"pronunciation/reading (e.g., hiragana for Japanese)\",\n \"meaning\": \"definition in English or target language\",\n \"notes\": \"grammar notes, usage tips, etc.\"\n}", "field_mapping": { "expression": "Expression", "reading": "Reading", "meaning": "Meaning", "notes": "Notes" }, "context_sentences": 1 } Restart Anki Configuration Getting an API Key The add-on works with Google's Gemini API, which offers generous free tier limits. Visit Google AI Studio Click "Create API key" Copy the generated key Setting up the Add-on In Anki, go to Tools → AI Vocab Card Generator Config Paste your API key in the "API Key" field Customize the prompt template if needed Map AI response fields to your Anki note fields Save the configuration Prompt Template The prompt template supports the following placeholders: {{subtitle}} - The main sentence or subtitle text {{contextBefore}} - Previous sentences for context {{contextAfter}} - Following sentences for context {{source}} - Source material information The default configuration includes an example prompt template optimized for Japanese vocabulary cards. Field Mapping Define how AI-generated fields map to your Anki note type: | AI JSON Key | Anki Field Name | |-------------|-----------------| | expression | Expression | | reading | Reading | | meaning | Meaning | | notes | Notes | Add or remove mappings as needed for your card template. Usage Basic Workflow Create a new card in Anki (or use with asbplayer for subtitle mining) Fill in the sentence/subtitle field Click the "Generate with AI" button or press Ctrl+Shift+G The add-on will automatically populate the configured fields Review and save the card Keyboard Shortcut Ctrl+Shift+G - Generate card fields with AI Supported APIs The add-on automatically detects the API type based on the endpoint: Google Gemini - Detects generativelanguage.googleapis.com in the endpoint OpenAI - Default format for other endpoints To switch APIs, simply change the endpoint URL and API key in the configuration. OpenAI Configuration Example { "api_endpoint": "https://api.openai.com/v1/chat/completions", "api_key": "sk-...", "model": "gpt-4" } Troubleshooting "Please configure your API key" error Make sure you've entered your API key in the configuration dialog. "No subtitle text found" error The add-on looks for text in fields named: Sentence, Subtitle, Text, or Expression. Ensure at least one of these fields contains text before generating. Authentication errors For Google Gemini, verify your API key is correct and has not expired. You can test it directly at Google AI Studio . No fields updated Check that your field mapping matches your note type's field names exactly. Field names are case-sensitive. Advanced Usage Custom AI Endpoints The add-on can work with any LLM API that accepts JSON requests and returns text responses. You may need to modify the call_ai_api() function for APIs with different request/response formats. Context Sentences Adjust the "Context sentences to include" setting to provide more surrounding text to the AI. This can improve accuracy for ambiguous terms but will use more API tokens. License This add-on is provided as-is for personal use with Anki.

GitHub repository: 25thdg/anki-ai-vocab-card-generator
Languages: Python