{
  "openapi": "3.1.0",
  "info": {
    "title": "Cross Context Universal AI Portability API",
    "version": "1.0.0",
    "description": "Universal conversation portability protocol and API bridging state across ChatGPT, Claude, Gemini, Grok, and Perplexity.\n\n### Versioning Policy\nThe Cross Context API uses explicit URL path versioning (`/api/v1/`). Major versions introduce non-backward-compatible modifications. Backward-compatible enhancements, optional properties, and new endpoints are introduced without incrementing the major version.\n\n### Deprecation Policy\nDeprecated endpoints and features are marked with `deprecated: true` in this OpenAPI specification and emit HTTP `Deprecation: @<timestamp>` and `Sunset: <date>` headers on all responses at least 6 months prior to decommissioning.\n\n### Rate Limiting Policy\nRequests are throttled according to IETF RateLimit standards. Responses include `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset`, and `RateLimit-Policy`. If limits are exceeded, the API responds with HTTP 429 and a `Retry-After` header alongside a typed `ProblemDetails` error.",
    "contact": {
      "name": "Cross Context Developer Support",
      "email": "support@cross-context.dev",
      "url": "https://cross-context.vercel.app/contact"
    },
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    },
    "x-versioning-policy": "URL path versioning (/v1/).",
    "x-deprecation-policy": "6-month sunset window with standard HTTP Deprecation and Sunset headers.",
    "x-rate-limit-policy": "120 requests per minute with standard IETF RFC RateLimit headers."
  },
  "servers": [
    {
      "url": "https://cross-context.vercel.app",
      "description": "Production API Server"
    }
  ],
  "paths": {
    "/api/v1/context": {
      "get": {
        "operationId": "getContextPacketV1",
        "summary": "Retrieve Universal Context Packet Specification",
        "description": "Returns the active conversation packet schema, instructions, and sample payload.",
        "responses": {
          "200": {
            "description": "Context packet specification and sample data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContextPacket"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "importContextPacketV1",
        "summary": "Import and Process Universal Context Packet",
        "description": "Receives, parses, and normalizes an active conversation packet from an AI platform.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContextPacket"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Context packet imported successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContextPacketResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON or malformed packet",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed against schema",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/context/validate": {
      "post": {
        "operationId": "validateContextPacketV1",
        "summary": "Validate Context Packet Schema",
        "description": "Validates a JSON context packet against the Open Context Exchange format and returns diagnostic metrics.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContextPacket"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validation outcome",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request payload",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/models": {
      "get": {
        "operationId": "getSupportedModelsV1",
        "summary": "List Supported LLM Platforms & Models",
        "description": "Returns the catalog of supported frontier AI platforms and foundation models.",
        "responses": {
          "200": {
            "description": "Catalog of supported models",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelCatalog"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/health": {
      "get": {
        "operationId": "getApiHealthV1",
        "summary": "Get API Health & Versioning Status",
        "description": "Returns operational status, API version, and deprecation policies.",
        "responses": {
          "200": {
            "description": "Operational health check",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthInfo"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/.well-known/mcp": {
      "get": {
        "operationId": "getMcpHandshake",
        "summary": "Model Context Protocol Handshake Discovery",
        "description": "Returns Model Context Protocol metadata, capabilities, and tools list.",
        "responses": {
          "200": {
            "description": "MCP handshake response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/McpServerInfo"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "executeMcpJsonRpc",
        "summary": "Model Context Protocol Streamable JSON-RPC Endpoint",
        "description": "Handles JSON-RPC 2.0 requests for tool calling, initialization, and conversation context exchange.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/JsonRpcRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonRpcResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON-RPC request",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ProblemDetails": {
        "type": "object",
        "description": "RFC 9457 Problem Details error schema",
        "required": ["type", "title", "status", "code", "detail"],
        "properties": {
          "type": {
            "type": "string",
            "format": "uri",
            "description": "URI identifier that categorizes the problem type",
            "example": "https://cross-context.vercel.app/docs/errors#resource-not-found"
          },
          "title": {
            "type": "string",
            "description": "Short, human-readable summary of the problem type",
            "example": "Resource Not Found"
          },
          "status": {
            "type": "integer",
            "description": "HTTP status code generated by origin server",
            "example": 404
          },
          "code": {
            "type": "string",
            "description": "Machine-readable specific error code",
            "example": "RESOURCE_NOT_FOUND"
          },
          "detail": {
            "type": "string",
            "description": "Human-readable explanation specific to this occurrence of the problem",
            "example": "The requested API endpoint was not found."
          },
          "instance": {
            "type": "string",
            "description": "URI reference that identifies the specific occurrence of the problem",
            "example": "/api/v1/context"
          },
          "resolution": {
            "type": "string",
            "description": "Actionable guidance or hint for AI agents to self-correct",
            "example": "Check available routes in the OpenAPI specification at https://cross-context.vercel.app/openapi.json"
          }
        }
      },
      "ContextPacket": {
        "type": "object",
        "required": ["version", "source", "messages"],
        "properties": {
          "$schema": { "type": "string", "example": "https://cross-context.vercel.app/schemas/context-packet-v1.json" },
          "version": { "type": "string", "example": "1.0.0" },
          "timestamp": { "type": "string", "format": "date-time" },
          "source": {
            "type": "object",
            "required": ["platform", "model"],
            "properties": {
              "platform": { "type": "string", "enum": ["chatgpt", "claude", "gemini", "grok", "perplexity"] },
              "model": { "type": "string", "example": "claude-3-7-sonnet" },
              "conversation_id": { "type": "string", "example": "conv_9f8a7e" },
              "title": { "type": "string", "example": "Database Optimization Heuristics" }
            }
          },
          "metrics": {
            "type": "object",
            "properties": {
              "total_turns": { "type": "integer", "example": 6 },
              "user_messages": { "type": "integer", "example": 3 },
              "assistant_messages": { "type": "integer", "example": 3 },
              "estimated_tokens": { "type": "integer", "example": 4250 }
            }
          },
          "system_instructions": { "type": "string", "example": "You are a senior database engineer." },
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["role", "content"],
              "properties": {
                "role": { "type": "string", "enum": ["user", "assistant", "system"] },
                "content": { "type": "string", "example": "How do I optimize indexes for multi-column JSONB filtering?" },
                "timestamp": { "type": "string", "format": "date-time" },
                "code_snippets": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "language": { "type": "string", "example": "sql" },
                      "code": { "type": "string", "example": "CREATE INDEX idx ON events USING GIN (payload);" }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "ContextPacketResponse": {
        "type": "object",
        "properties": {
          "valid": { "type": "boolean", "example": true },
          "version": { "type": "string", "example": "1.0.0" },
          "turns_count": { "type": "integer", "example": 6 },
          "status": { "type": "string", "example": "accepted" },
          "message": { "type": "string", "example": "Context packet parsed and validated successfully." }
        }
      },
      "ValidationResult": {
        "type": "object",
        "properties": {
          "valid": { "type": "boolean", "example": true },
          "errors": { "type": "array", "items": { "type": "string" } },
          "turns_analyzed": { "type": "integer", "example": 6 },
          "estimated_tokens": { "type": "integer", "example": 4250 }
        }
      },
      "ModelCatalog": {
        "type": "object",
        "properties": {
          "version": { "type": "string", "example": "1.0.0" },
          "platforms": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": { "type": "string" },
                "name": { "type": "string" },
                "supported_models": { "type": "array", "items": { "type": "string" } },
                "status": { "type": "string" }
              }
            }
          }
        }
      },
      "HealthInfo": {
        "type": "object",
        "properties": {
          "status": { "type": "string", "example": "operational" },
          "version": { "type": "string", "example": "1.0.0" },
          "service": { "type": "string", "example": "Cross Context Universal AI Portability API" },
          "versioning_policy": { "type": "string" },
          "documentation": { "type": "string" },
          "openapi": { "type": "string" },
          "timestamp": { "type": "string", "format": "date-time" }
        }
      },
      "McpServerInfo": {
        "type": "object",
        "properties": {
          "name": { "type": "string", "example": "cross-context-mcp" },
          "version": { "type": "string", "example": "1.0.0" },
          "protocolVersion": { "type": "string", "example": "2024-11-05" },
          "capabilities": { "type": "object" },
          "tools": { "type": "array", "items": { "type": "object" } }
        }
      },
      "JsonRpcRequest": {
        "type": "object",
        "required": ["jsonrpc", "method", "id"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"], "example": "2.0" },
          "id": { "type": ["string", "integer"], "example": 1 },
          "method": { "type": "string", "example": "tools/list" },
          "params": { "type": "object" }
        }
      },
      "JsonRpcResponse": {
        "type": "object",
        "required": ["jsonrpc", "id"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"], "example": "2.0" },
          "id": { "type": ["string", "integer"], "example": 1 },
          "result": { "type": "object" },
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "integer" },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
