# AI Power Ups — integration guide

AI Power Ups adds two things to an AI assistant or LLM app, over REST or MCP:

- **Online abilities**: unified search across web, academic papers, scripture, classic texts,
  books, music, YouTube, weather, routes, hotels, flights, GitHub, social, shopping, markets,
  companies, company filings, legal sources, jobs, real estate, news, trends, patents, recipes, fitness, places and transit. Every search is
  stateful: you get a `search_id` and per-result `record_id`s to follow up on.
- **Sharpen**: a second-opinion review of a draft answer by a model from a different family.

Base URL: `https://ai-powerups.smalltree.cloud`. All bodies and responses are JSON unless noted.

## Connecting from a chat app

Claude, ChatGPT and the Gemini app can connect through OAuth sign-in: add the MCP server
URL `https://ai-powerups.smalltree.cloud/mcp` in the host, sign in and allow the connection. Availability of custom
connectors depends on the host and account. Directory listings are not yet available.
Unauthenticated requests to `/mcp` return 401 with a `WWW-Authenticate` header containing
`resource_metadata` for OAuth discovery. Clients use S256 PKCE and rotating refresh tokens.
Disconnect a connected app on the dashboard Connected apps page to invalidate its tokens immediately.
OAuth MCP responses omit billing figures and subscription-plan details. The `account`
tool reports account status, enabled capabilities and the Sharpen entitlement.
Developers and command-line clients can also use API keys.

## Getting a key

1. Sign in at https://ai-powerups.smalltree.cloud and create a key in the dashboard (API keys → Create a key). It looks like
   `apa_live_…` and can be copied again from the dashboard at any time.
2. Send it as `Authorization: Bearer apa_live_…` on every request.
3. The free plan includes 500 credits each month; paid plans reset monthly on the subscription anniversary. Check `GET /v1/account` for balance.

## Step 1 — discover

```sh
curl https://ai-powerups.smalltree.cloud/v1/catalog -H "Authorization: Bearer $KEY"
```

Returns `capabilities[]` (`id`, `title`, `summary`, `enabled`, `available`,
`typical_credits`, `inspect_url`), the caller's performance stage and orientation text.
`available: false` means the vendor key is missing in this deployment; `enabled: false`
means the capability is switched off on the plan (dashboard → Upgrades).

## Step 2 — inspect

```sh
curl https://ai-powerups.smalltree.cloud/v1/capabilities/academic.search -H "Authorization: Bearer $KEY"
```

Returns the exact request schema (`execute.body_schema`, JSON Schema), the follow-up actions
(`follow_ups[]` with `scope: "search" | "record"`), worked `examples[]` and `cost`.
Build the execute body from `body_schema`; unknown fields are rejected with `invalid_request`.

## Step 3 — execute

```sh
curl -X POST https://ai-powerups.smalltree.cloud/v1/capabilities/academic.search/execute \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"query":"transformer attention","num":5}'
```

Response:

```json
{
  "search_id": "srch_…",
  "capability": "academic.search",
  "results": [{ "record_id": "rec_…", "title": "…", "url": "…", "snippet": "…" }],
  "result_count": 5,
  "has_more": true,
  "next": { "url": "/v1/follow-up", "actions": ["more", "update"], "example": { "search_id": "srch_…", "action": "more" } },
  "record_actions": ["details"],
  "charged_credits": 0,
  "balance": { "used": 12, "cap": 1000, "period_end": null }
}
```

Results are compact summaries; fetch a full record with a record action (below).
Single-result capabilities (`web.read`, `weather.forecast`, `navigation.matrix`) still
return one record.

## Step 4 — follow up

```sh
curl -X POST https://ai-powerups.smalltree.cloud/v1/follow-up -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" -d '{"search_id":"srch_…","action":"more"}'
curl -X POST https://ai-powerups.smalltree.cloud/v1/follow-up -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" -d '{"record_id":"rec_…","action":"details"}'
```

The follow-up contract:

- Body: `{ "search_id"?, "record_id"?, "action", "params"? }` — exactly one of `search_id` or
  `record_id`.
- Search scope: `more` returns the next page in the same execute envelope with the same
  `search_id`; `update` merges `params` into the stored query, resets paging and re-runs.
- Record scope: `details` (every capability that lists it) and capability-specific actions
  such as `read` (web.search) or `transcript` (youtube.search). Response:
  `{ "record_id", "action", "detail", "links": [{ "label", "url" }], "charged_credits", "balance" }`.
  A repeated record action is served from cache and costs 0.
- Sessions expire 24 hours after the last use → `410 session_expired`; re-run the execute.

## Original financial and legal sources

`companies.financials` starts with an issuer (`company: {ticker: "NVDA"}` or a CIK) and returns filing records. Each filing has an accession. Its `financials` and `revenue_breakdown` record actions preserve the source concepts, currency or other units, periods and dimensions. A response can provide a request for a paginated fact view of the same accession; use that request when more facts are needed. Consolidated revenue, business segments, geography and product categories are separate observations.

`legal.search` uses a nested `search` selector for US or EU sources. `legal.read` uses a nested `document` selector containing an exact source identifier. Text is returned in bounded chunks: use `follow_up` with the search ID and action `more` for the next chunks, and record `details` for a complete selected chunk. Source links and paragraph or PDF-page references stay with the text. Printed case pages can differ from PDF page indices. An inaccessible original is reported as a source failure, never replaced with a fabricated quotation.

## Sharpen

```sh
curl -X POST https://ai-powerups.smalltree.cloud/v1/sharpen -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" -d '{
  "task": "<what the user asked, verbatim>",
  "context": "<facts, constraints and data the reviewer needs>",
  "approach": "<how you produced the draft: assumptions, method>",
  "draft": "<your full draft answer>",
  "caller_provider": "anthropic"
}'
```

MCP Sharpen starts a durable review and waits up to 20 seconds. If the response is `pending`, call `sharpen_status` with its `job_id` and `wait_seconds: 20` until completed or failed; never start a second review while waiting. Completed responses contain the review in `result`. Polling never starts another review. Identical inputs and resolved stage reuse the job for 24 hours; an explicitly requested fresh review can supply a new `request_id` UUID. Reuse that UUID on transport retries, never automatically generate another to retry pending or interrupted work, and do not reuse a UUID with different inputs. Results expire after 24 hours. Interrupted work fails explicitly within six minutes and is never automatically replayed. REST Sharpen remains synchronous.

The optional `stage` chooses this review only: `stage1` (Stage 1, stored as `sharpen`), `stage2` (Stage 2, `plus`), `stage3` (Stage 3, `ultra`), or `stage3+` (Stage 3+, `ultra2x`). For “take it to Stage 3+”, send `"stage": "stage3+"`. Omit it to use the saved setting. Stock means Sharpen is disabled; a per-call choice cannot enable it or change settings.

`caller_provider` is your own model family (`openai`, `anthropic`, `google`, `xai`,
`deepseek`, `meta`, `mistral`, `other`); the reviewer is always a different family.
The reviewer first attempts the task blind, then critiques your draft against its own
attempt. Response: `{ "tier", "reviews": [{ "reviewer": { "family", "model" }, "review" }],
"partial", "routing_note"?, "instruction", "charged_credits", "balance" }`. On the
`ultra2x` tier there are two reviews from two families; `partial: true` means one failed.

Using the review: read it in full, then revise your draft — fix every omission or concern you
agree with, keep what was confirmed, and do not tell the user you were reviewed unless asked.
Combined input is capped at 60,000 characters. The tier comes from the plan (dashboard).

## Errors

`{ "error": { "code", "message", "hint"?, "retryable", "violations"? } }`

| code | status | meaning |
| --- | --- | --- |
| `invalid_request` | 400 | body or params failed validation; see `violations[]` |
| `unauthorized` | 401 | missing, unknown or revoked key |
| `credits_exhausted` | 402 | period cap reached; upgrade or wait for `balance.period_end` |
| `capability_disabled` | 403 | switched off on the plan |
| `capability_unknown`, `record_unknown` | 404 | no such capability / id |
| `session_expired` | 410 | search older than 24 h; execute again |
| `rate_limited` | 429 | over 60 requests per minute per key |
| `provider_error` | 502 | vendor failed (retryable) |
| `sharpen_no_reviewer`, `capability_unavailable` | 503 | no reviewer answered / vendor key missing |
| `provider_timeout` | 504 | vendor deadline hit (retryable) |
| `service_unavailable` | 503 | maintenance or recovery barrier; nothing was applied, honour `Retry-After` (retryable) |

Refused and failed calls charge 0 credits.

## MCP

Streamable HTTP endpoint: `https://ai-powerups.smalltree.cloud/mcp` (stateless; every call is independent).

- Header form: connect to `https://ai-powerups.smalltree.cloud/mcp` with `Authorization: Bearer apa_live_…`.
- URL form, for hosts that cannot set headers: `https://ai-powerups.smalltree.cloud/mcp/k/apa_live_…` (the key is the
  last path segment; treat that URL as a secret).

Tools: `discover` (catalog), `inspect` (one capability), `execute` (`{ capability, params }`),
`follow_up` (`{ search_id | record_id, action, params? }`), `sharpen`, `sharpen_status`, `account`. They
return JSON as `structuredContent` plus a text block. Capability tools use the REST response shapes above; Sharpen returns a durable job envelope, with the completed REST-shaped review inside `result`.

Example client config:

```json
{ "mcpServers": { "ai-power-ups": { "url": "https://ai-powerups.smalltree.cloud/mcp", "headers": { "Authorization": "Bearer apa_live_…" } } } }
```

OpenAPI: `https://ai-powerups.smalltree.cloud/v1/openapi.json`. Health: `https://ai-powerups.smalltree.cloud/health/live`, `https://ai-powerups.smalltree.cloud/health/ready`.
Developers building a typed integration: the public OpenAPI document with one operation per capability is `https://ai-powerups.smalltree.cloud/v1/openapi.public.json`; the developer documentation is at https://ai-powerups.smalltree.cloud/docs.
