# Managed RAG bundle

GEDX402 sells managed RAG instances as one discoverable family. Agents pay USDC via x402 — no API keys.

**Discovery:** `GET https://gedx402.com/v1/models?bundle=managed-rag` — five routes tagged `managed-rag-bundle`.

| Step | Route | Shard | Method |
| --- | --- | --- | --- |
| **RAG answer (hero)** | `/v1/aisearch/outcome/answer` | aisearch | `POST` |
| Prepaid session (advanced) | `/v1/aisearch/sessions` | aisearch | `POST` |
| Create instance | `/v1/aisearch/instances` | aisearch | `POST` |
| Ingest | `/v1/aisearch/:id/index` | aisearch | `POST` |
| Query | `/v1/aisearch/:id/query` | aisearch | `POST` |
| MCP URL | `/v1/aisearch/:id/mcp` | aisearch | `GET` (free) |

Origin: `rag.gedx402.com`. Paid routes return `402` with x402 payment instructions until settled — except index/query when a valid `session_token` from `/v1/aisearch/outcome/answer` or `/v1/aisearch/sessions` has remaining credits.

**Starter route:** `POST https://rag.gedx402.com/v1/aisearch/outcome/answer` (`starter:true` in agents.json).

**Hero page:** `https://gedx402.com/heroes/rag-answer`

---

## Integration flow (single-hop)

```mermaid
sequenceDiagram
  participant Agent
  participant Answer as POST /v1/aisearch/outcome/answer
  participant Query as POST /v1/aisearch/:id/query

  Agent->>Answer: url(s), question, budget?
  Note over Answer: one x402 payment
  Answer-->>Agent: cited answer, session_token, query_path, credits
  Agent->>Query: session_token header (no 402 while credits remain)
  Query-->>Agent: chunks[], credits remaining
```

### 1. RAG answer (recommended)

Single-hop cited answer — indexes URL(s), hybrid retrieval, synthesizes via chat/fast, and mints prepaid follow-up query credits:

```http
POST https://rag.gedx402.com/v1/aisearch/outcome/answer
Content-Type: application/json

{
  "url": "https://example.com/docs",
  "question": "How do I configure managed RAG?",
  "budget": { "max_queries": 5 }
}
```

One x402 payment covers indexing, answer synthesis, and prepaid query credits. Response includes `session_token`, `query_path`, `credits`, and the cited natural-language answer.

Send `session_token` on follow-up query calls:

```http
POST https://rag.gedx402.com/v1/aisearch/ged-abc123/query
X-AISearch-Session-Token: <session_token>
Content-Type: application/json

{ "query": "What are the rate limits?" }
```

Or pass `session_token` in the JSON body. No `402` until `queries_remaining` hits zero.

### 2. Prepaid session (advanced — multi-hop)

For agents that want separate create/index/query legs instead of the single-hop answer:

```http
POST https://rag.gedx402.com/v1/aisearch/sessions
Content-Type: application/json

{
  "initial_index": { "url": "https://example.com/docs" },
  "query": "How do I configure managed RAG?",
  "budget": { "max_index_ops": 1, "max_queries": 1 }
}
```

Hero: `GET https://gedx402.com/heroes/rag-session`. Not in the default `?bundle=winners` funnel.

### 3. Create instance (multi-hop)

```http
POST https://rag.gedx402.com/v1/aisearch/instances
Content-Type: application/json

{}
```

Response includes `instance_id`, `index_path`, and `query_path`. Optional body field `id` sets a custom instance slug (lowercase, hyphens).

### 4. Index content

```http
POST https://rag.gedx402.com/v1/aisearch/ged-abc123/index
Content-Type: application/json

{ "url": "https://example.com/docs" }
```

Also accepts `text`, `file_base64`, and `filename`. Set `"poll": true` to block until indexing completes.

### 5. Hybrid query

```http
POST https://rag.gedx402.com/v1/aisearch/ged-abc123/query
Content-Type: application/json

{
  "query": "How do I configure managed RAG?",
  "top_k": 5,
  "retrieval_type": "hybrid"
}
```

Returns ranked chunks with scores and metadata. Optional `rewrite_query` and `rerank` flags.

`GET /v1/aisearch/:id/mcp` returns 410 and `query_path`.

---

## Pricing and limits

- **RAG answer:** one x402 quote = index + answer synthesis + `budget.max_queries` follow-up credits (default 5, max 10; max 5 URLs).
- **Sessions (advanced):** one x402 quote = create + `budget.max_index_ops` × index + `budget.max_queries` × query (defaults 1/1; max 5 / 10).
- **Index upload:** max **65536** bytes per `url` / `text` / `file_base64` (flat index price; larger uploads are refused).
- **Instance TTL:** new instances expire after **7 days idle**; index/query activity extends the window.
- **Per-route:** USDC on create, index, and query when not using session credits.
- `GET /v1/aisearch/:id/mcp` is free.

See `GET /v1/models?bundle=managed-rag` for **USDC wire settlement** per leg.

---

## Agent discovery

- Hub catalog: `GET /v1/models?bundle=managed-rag`
- Hero SKUs: `GET /v1/models?prominence=hero`
- OpenAPI: `https://rag.gedx402.com/openapi.json`
- x402scan tags: `managed-rag-bundle`, `rag`
- MCP starter: `gedx402_aisearch_outcome_answer`
- Shard ops reference: [AI-SEARCH-SHARD.md](./AI-SEARCH-SHARD.md)
- vs self-serve semantic memory: see [RAG-BUNDLE.md](./RAG-BUNDLE.md) for `embed` + `search` shards
