{
	"openapi": "3.1.0",
	"info": {
		"title": "ReplayPilot Ingest API",
		"version": "1.0.0",
		"description": "Public HTTP endpoints for sending data into ReplayPilot: Sentry-compatible error ingestion and source map uploads. The recording snippet's own wire protocol (/ingest) isn't included -- it's internal to the snippet, not a documented integration surface. For querying data back out as an agent, see the MCP server card at /.well-known/mcp.json. Every response carries an `API-Version` header (currently `1`, bumps on a breaking change) and `RateLimit-Limit`/`RateLimit-Policy` headers (60 requests/minute per IP on every endpoint here)."
	},
	"servers": [{ "url": "https://ingest.replaypilot.com" }],
	"paths": {
		"/api/{projectId}/envelope/": {
			"post": {
				"operationId": "ingestSentryEnvelope",
				"summary": "Sentry-compatible error/session envelope ingestion",
				"description": "Accepts Sentry's envelope wire format (https://develop.sentry.dev/sdk/data-model/envelopes/), so any official Sentry SDK works unmodified by pointing its `dsn` at ReplayPilot. The numeric path segment is only present because Sentry DSNs require one; ReplayPilot ignores it and identifies the project from `sentry_key` instead. See https://replaypilot.com/docs/errors.",
				"parameters": [
					{
						"name": "projectId",
						"in": "path",
						"required": true,
						"schema": { "type": "string" },
						"description": "Ignored -- present only because Sentry SDKs require a DSN path segment."
					},
					{
						"name": "sentry_key",
						"in": "query",
						"required": false,
						"schema": { "type": "string" },
						"description": "Project public key (pk_live_...). Required unless sent via the X-Sentry-Auth header instead."
					}
				],
				"requestBody": {
					"required": true,
					"content": {
						"application/x-sentry-envelope": {
							"schema": {
								"type": "string",
								"description": "Newline-delimited envelope: one header line, then item header/payload line pairs. Only \"event\" and \"session\" item types are read."
							}
						}
					}
				},
				"responses": {
					"200": { "description": "Accepted" },
					"400": { "$ref": "#/components/responses/Error" },
					"403": { "$ref": "#/components/responses/Error" },
					"413": { "$ref": "#/components/responses/Error" },
					"429": { "$ref": "#/components/responses/RateLimited" }
				}
			}
		},
		"/api/sourcemaps": {
			"post": {
				"operationId": "uploadSourceMap",
				"summary": "Upload a source map for a release",
				"description": "Typically called from a CI/build step, not by hand. See https://replaypilot.com/docs/releases.",
				"security": [{ "projectSecretKey": [] }],
				"requestBody": {
					"required": true,
					"content": {
						"application/json": {
							"schema": {
								"type": "object",
								"required": ["release", "filename", "map"],
								"properties": {
									"release": {
										"type": "string",
										"description": "Version string reported by your Sentry SDK. Must not contain / or \\."
									},
									"filename": { "type": "string" },
									"map": {
										"type": "object",
										"description": "The source map JSON itself."
									}
								}
							}
						}
					}
				},
				"responses": {
					"200": {
						"description": "Stored; replaces any existing map for the same release + filename."
					},
					"400": { "$ref": "#/components/responses/Error" },
					"401": { "$ref": "#/components/responses/Error" },
					"403": { "$ref": "#/components/responses/Error" },
					"413": { "$ref": "#/components/responses/Error" },
					"429": { "$ref": "#/components/responses/RateLimited" }
				}
			}
		},
		"/recording-config": {
			"get": {
				"operationId": "getRecordingConfig",
				"summary": "Fetch a project's path-based recording rules",
				"description": "Called by the browser snippet at load time; documented here for anyone building their own client against a project key.",
				"parameters": [
					{
						"name": "projectId",
						"in": "query",
						"required": true,
						"schema": { "type": "string" },
						"description": "Project public key (pk_live_...)."
					}
				],
				"responses": {
					"200": {
						"description": "OK",
						"content": {
							"application/json": {
								"schema": {
									"type": "object",
									"properties": {
										"rules": {
											"type": "array",
											"items": {
												"type": "object",
												"properties": {
													"pathPattern": { "type": "string" },
													"ignoreSessions": { "type": "boolean" },
													"ignoreLogs": { "type": "boolean" },
													"ignoreErrors": { "type": "boolean" },
													"ignoreFrustration": { "type": "boolean" }
												}
											}
										}
									}
								}
							}
						}
					},
					"400": { "$ref": "#/components/responses/Error" },
					"404": { "$ref": "#/components/responses/Error" },
					"429": { "$ref": "#/components/responses/RateLimited" }
				}
			}
		}
	},
	"components": {
		"securitySchemes": {
			"projectSecretKey": {
				"type": "http",
				"scheme": "bearer",
				"description": "Project secret key (sk_live_...), from that project's Keys tab. Also authenticates the MCP server."
			}
		},
		"schemas": {
			"Error": {
				"type": "object",
				"properties": {
					"error": { "type": "string", "description": "Human-readable message." },
					"code": {
						"type": "string",
						"description": "Machine-readable, derived from the HTTP status.",
						"enum": [
							"bad_request",
							"unauthorized",
							"forbidden",
							"not_found",
							"method_not_allowed",
							"payload_too_large",
							"upgrade_required",
							"rate_limited",
							"service_unavailable",
							"error"
						]
					}
				},
				"required": ["error", "code"]
			}
		},
		"headers": {
			"RetryAfter": {
				"description": "Seconds until the per-IP rate limit window resets. Fixed at 60 -- every limiter here shares a 60 requests/minute window.",
				"schema": { "type": "integer", "example": 60 }
			},
			"RateLimitLimit": {
				"description": "Requests allowed per window, on every response, not just a 429.",
				"schema": { "type": "integer", "example": 60 }
			},
			"RateLimitPolicy": {
				"description": "IETF draft RateLimit-Policy: quota;w=window_seconds.",
				"schema": { "type": "string", "example": "60;w=60" }
			}
		},
		"responses": {
			"Error": {
				"description": "Error",
				"content": {
					"application/json": { "schema": { "$ref": "#/components/schemas/Error" } }
				}
			},
			"RateLimited": {
				"description": "Rate limited (60 requests/minute per IP)",
				"headers": { "Retry-After": { "$ref": "#/components/headers/RetryAfter" } },
				"content": {
					"application/json": { "schema": { "$ref": "#/components/schemas/Error" } }
				}
			}
		}
	}
}
