AI
Pass

AI Flashcard Generator — Agent Skill

AI Flashcard Generator — Agent Skill

Generate flashcards from notes using AI Pass chat completions.

Setup

Get API key: https://aipass.one/panel/developer.html → API Keys

export AIPASS_API_KEY="your-key-here"

Generate Flashcards

import requests
import os
import json

AIPASS_API_KEY = os.environ["AIPASS_API_KEY"]

def generate_flashcards(notes, count=10):
    """Generate flashcards from notes.
    
    Args:
        notes: Text content to create flashcards from
        count: Number of flashcards to generate
    
    Returns:
        List of flashcard dictionaries with 'question' and 'answer'
    """
    
    response = requests.post(
        "https://aipass.one/apikey/v1/chat/completions",
        headers={
            "Authorization": f"Bearer {AIPASS_API_KEY}",
            "Content-Type": "application/json"
        },
        json={
            "model": "gpt-5-mini",
            "messages": [
                {
                    "role": "system",
                    "content": "You are a study expert. Create flashcards from the provided notes. Return a valid JSON array with objects containing 'question' and 'answer' fields. Ensure the JSON is parseable."
                },
                {
                    "role": "user",
                    "content": f"Create {count} flashcards from these notes:\n\n{notes}"
                }
            ]
        }
    )
    
    if response.status_code != 200:
        raise Exception(f"Error: {response.text}")
    
    content = response.json()["choices"][0]["message"]["content"]
    
    # Try to parse JSON - sometimes models wrap in markdown
    try:
        cards = json.loads(content)
    except json.JSONDecodeError:
        # Try to extract JSON from markdown code block
        if '```json' in content:
            json_str = content.split('```json')[1].split('```')[0].strip()
            cards = json.loads(json_str)
        elif '```' in content:
            json_str = content.split('```')[1].split('```')[0].strip()
            cards = json.loads(json_str)
        else:
            raise Exception(f"Could not parse JSON from response: {content[:200]}...")
    
    return cards

# Example usage
if __name__ == "__main__":
    notes = """
    Photosynthesis is the process plants use to convert sunlight into energy.
    Chlorophyll is the green pigment in plants that absorbs light.
    Carbon dioxide and water are the raw materials for photosynthesis.
    Oxygen and glucose are the products of photosynthesis.
    """
    
    cards = generate_flashcards(notes, 5)
    for i, card in enumerate(cards, 1):
        print(f"Q{i}: {card['question']}")
        print(f"A{i}: {card['answer']}")
        print()

Export to Anki

def export_anki(cards, filename="flashcards.txt"):
    """Export flashcards to Anki import format."""
    with open(filename, 'w') as f:
        for card in cards:
            # Anki format: front side <separator> back side <separator> tags
            f.write(f"{card['question']}\t{card['answer']}\t\n")
    print(f"Exported {len(cards)} cards to {filename}")

Notes

  • Model: gpt-5-mini (best balance)
  • Output: JSON array with question/answer
  • Works with: Anki, Quizlet, and other flashcard apps
  • Tip: Use clear, structured notes for better results