# Spec Slice — OpenAPI & GraphQL Subgraph Extractor (v1.0.0)

> Shrink 200k-token OpenAPI 3.1 and GraphQL schemas by 90-99% into valid, cycle-safe mini-specs in <20ms.

Surgical OpenAPI 3.0/3.1, Swagger 2.0, and GraphQL SDL subgraph slicer for coding and tool-use agents. Ranks operations by BM25 intent + structural boosts and extracts the exact cycle-safe transitive closure of referenced schemas, parameters, unions, interfaces, inputs, and enums.

## Why Agents Use This API Instead of DIY
Eliminates context-window overflow on massive Stripe/GitHub/Shopify specs, avoids broken $ref pointers or infinite recursive schema loops, and saves $0.10-$0.50 in LLM input tokens for $0.001.

## Connection & Payment (x402 Default + Optional Bearer API Key)
- **MCP Server (Streamable HTTP):** `https://spec-slice.apikeg.com/mcp` (Registry ID: `com.apikeg/spec-slice` — `initialize`, `tools/list`, `resources/*`, and `prompts/*` are free)
- **OpenAPI 3.1 Spec:** [openapi.json](https://spec-slice.apikeg.com/openapi.json)
- **Full Schema & Examples:** [llms-full.txt](https://spec-slice.apikeg.com/llms-full.txt)
- **RFC 9727 API Catalog:** [.well-known/api-catalog](https://spec-slice.apikeg.com/.well-known/api-catalog)
- **x402 Bazaar Manifest:** [.well-known/x402.json](https://spec-slice.apikeg.com/.well-known/x402.json)
- **MCP Discovery Manifest:** [.well-known/mcp.json](https://spec-slice.apikeg.com/.well-known/mcp.json)
- **A2A Agent Card:** [.well-known/agent-card.json](https://spec-slice.apikeg.com/.well-known/agent-card.json)
- **Primary Payment (Zero Signup):** Cloudflare Monetization Gateway (`HTTP 402` / `x402` v2 with USDC on Base).
- **Optional Monthly API Key:** Pass `Authorization: Bearer ak_live_...` ($5 / $20 / $50 monthly per-product Stripe plans at [apikeg.com/account](https://apikeg.com/account)).
- **Free Preflight:** Append `?dry_run=true` (or header `X-Dry-Run: true`) to validate any request payload at `$0.00` cost.

## Tools & REST Endpoints
- [`slice_openapi_spec`](https://spec-slice.apikeg.com/tools/slice-openapi-spec.md) (`POST https://spec-slice.apikeg.com/v1/slice-openapi-spec`) — $0.001 USD per OpenAPI/Swagger subgraph slice (x402 instant micropayment): Scores OpenAPI/Swagger endpoints against a natural-language `query` (BM25 + boosted `operationId`, `summary`, `tags`, and path tokens) or explicit `operationIds`/`pathPatterns`, walks every reachable JSON Pointer `$ref` with cycle protection, prunes unused paths/components, and emits ready-to-use `curl` + TypeScript `fetch` snippets.
- [`slice_graphql_schema`](https://spec-slice.apikeg.com/tools/slice-graphql-schema.md) (`POST https://spec-slice.apikeg.com/v1/slice-graphql-schema`) — $0.001 USD per GraphQL SDL subgraph slice (x402 instant micropayment): Parses GraphQL Schema Definition Language (`Query`, `Mutation`, `Subscription`, `type`, `input`, `interface`, `union`, `enum`, `scalar`), scores root fields against `query` or explicit `rootFields`, and emits a valid mini-SDL containing only selected root fields and the transitive closure of referenced types.

## Instant MCP Configuration
```json
{
  "mcpServers": {
    "spec-slice": {
      "type": "streamable-http",
      "url": "https://spec-slice.apikeg.com/mcp"
    }
  }
}
```

## Common Agent Use Cases
- slice large OpenAPI spec for LLM context window
- extract OpenAPI 3.1 endpoints and transitive $ref schemas
- prune GraphQL SDL schema to relevant Query and Mutation subgraph
- compress Swagger 2.0 JSON for AI coding agent
- generate curl and TypeScript fetch from OpenAPI operation
