Metadata-Version: 2.1
Name: retina-api
Version: 0.2.0
Summary: Retina's public API: a Python client, the `retina` CLI and the `retina-mcp` MCP server.
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: typer>=0.12
Requires-Dist: mcp<2.0,>=1.27
Description-Content-Type: text/markdown

# retina-api

Retina's public API for Python, in one package:

- `retina_sdk.RetinaClient`, an async client with one method per `/v1` operation.
- `retina`, a command line tool with one command per method.
- `retina-mcp`, an MCP server with one tool per method.

All three are made from the same operation table, so they always offer the same things.
The package depends only on `httpx`, `typer` and `mcp`.

## Quickstart: your own Claude Code on Retina

You bring the agent.
Retina gives it tools: research, generation, posting, and the numbers back.
Your agent runs where you run it; Retina only answers the calls it makes.

### 1. Install

```bash
pip install retina-api
```

This gives you two commands: `retina` and `retina-mcp`.

### 2. Set the key

Make a workspace key (it starts with `rk_`) in the Retina console.
Every command and tool reads it from `RETINA_API_KEY`.

```bash
export RETINA_API_KEY=rk_...
retina me
```

`retina me` prints your workspace and its credit balance.
`RETINA_API_BASE` changes the API address, and the default is `https://api.retina.dev`.

### 3. Add the server to Claude Code

```bash
claude mcp add retina --env RETINA_API_KEY=rk_... -- uvx --from retina-api retina-mcp
```

Or use the `retina-mcp` from the venv where you installed the package:

```bash
claude mcp add retina --env RETINA_API_KEY=rk_... -- /path/to/venv/bin/retina-mcp
```

Run `claude mcp list` to check that `retina` is connected.

Any other MCP client takes the same command in its JSON config:

```json
{
  "mcpServers": {
    "retina": {
      "command": "uvx",
      "args": ["--from", "retina-api", "retina-mcp"],
      "env": {"RETINA_API_KEY": "rk_..."}
    }
  }
}
```

The server has one tool per `/v1` operation, named `retina_<method>`.
A tool that fails returns the API's error object (`success: false`, `error.code`) instead of raising.
It still starts when it cannot reach the API; the tools then answer `network_error`.

### 4. A worked example

Ask Claude Code, in plain words:

> Read retina_guide. Then use retina_research_outliers to find what beats the usual views for "home espresso" in the last 30 days, with a budget of $0.50. Tell me the three best outliers and what they have in common.

Claude calls `retina_guide`, then `retina_research_outliers`, and reads the answer back to you.
The search is charged on success; `retina_me` shows what it cost.

The same steps from the shell:

```bash
retina guide
retina research-outliers --keywords "home espresso" --days 30 --budget-usd 0.5
retina me
```

From there the loop is `retina_generate_media` (or `retina_upload_file`) to make a post, `retina_create_post` to publish it to a linked account (`retina_connect_social` links one), and `retina_post_stats` to read how it did.

## The command line

```bash
retina catalog
retina generate-media --operation text_to_image --model <model> --prompt "a cat on a skateboard"
retina --help
```

Each command prints JSON.
`--jq <filter>` filters the output when `jq` is installed.
An API error exits 1 and prints the error JSON on stderr.
An API it cannot reach is the same, with the code `network_error`.
A missing key exits 2.

## The client

```python
import asyncio
from retina_sdk import RetinaClient

async def main() -> None:
    retina = RetinaClient.from_env()
    print(await retina.me())

asyncio.run(main())
```

## For Retina developers

The client is checked against `src/retina_sdk/v1_contract.json`.
That file is generated from the backend's own `/v1` spec by `backend/tests/test_the_v1_contract_the_clients_are_checked_against_is_current.py` with `RECORD_V1_CONTRACT=1`.
Do not edit it by hand.
When a `/v1` route changes, record the contract again, then add or change the method in `src/retina_sdk/client.py`.
The tests in `tests/` fail until the client matches.

`scripts/prove_the_wheel_installs.sh` builds the wheel, installs it into a clean venv, and starts `retina` and `retina-mcp` with only `RETINA_API_KEY` set.
It calls no real API.
