Metadata-Version: 2.4
Name: magic-answer
Version: 0.1.4
Summary: A lightweight OpenRouter client with Supabase-based remote API key storage.
Author: Melkii_Mel
License: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openai
Requires-Dist: requests
Requires-Dist: pyperclip
Dynamic: license-file

﻿# Magic Answer

A lightweight Python library for querying OpenRouter LLMs using API keys stored in a Supabase key-value database.

Instead of embedding an OpenRouter API key into your application, **Magic Answer** retrieves it from a Supabase key-value store at runtime using a lookup key. This allows API keys to be updated or rotated without modifying or redistributing client applications.

## Features

* Query any model available through OpenRouter
* Automatic fallback between multiple models
* Retrieve OpenRouter API keys from a Supabase key-value store
* Exceptionally simple Python API
* Optional clipboard integration
* Built-in key manager for maintaining the Supabase database
* Easily customizable through configuration

## Installation

```bash
pip install magic-answer
```

## Quick Start

Query using console input:

```python
import magic_answer

magic_answer.ask("your_lookup_key")
```

Or use the clipboard:

```python
import magic_answer

magic_answer.ask_clipboard("your_lookup_key")
```

## Managing API Keys

Magic Answer includes a simple graphical key manager for maintaining your Supabase key-value store.

```python
import magic_answer

magic_answer.open_key_manager()
```

The key manager allows you to:

* Add or update API keys
* Check whether a lookup key exists
* View the stored value associated with a lookup key

## Configuration

Override the default Supabase configuration:

```python
from magic_answer import config

config.SUPABASE_URL = "https://your-project.supabase.co"
config.SUPABASE_KEY = "your_supabase_anon_key"
config.CUSTOM_INSTRUCTION = "Your custom instruction"
```

Configure fallback models:

```python
from magic_answer import models

models.models = [
    "openai/gpt-oss-20b:free",
    "qwen/qwen3-235b-a22b:free",
    "deepseek/deepseek-r1:free",
]
```

The library will attempt each model in order until one successfully returns a response.

## API

### `ask(lookup_key)`

Prompts the user for a question, retrieves the corresponding OpenRouter API key from Supabase using `lookup_key`, queries OpenRouter, and prints the model's response.

### `ask_clipboard(lookup_key)`

Reads the prompt from the clipboard, retrieves the corresponding OpenRouter API key from Supabase, queries OpenRouter, and copies the model's response back to the clipboard.

### `open_key_manager()`

Opens the built-in HTML key manager in the default web browser, allowing you to add, update, and inspect entries in your Supabase key-value store.

## Requirements

* Python 3.10+
* Internet connection
* A Supabase project containing the key-value table
* An OpenRouter API key stored in that table

## License

MIT
