{
  "openapi": "3.1.0",
  "info": {
    "title": "Alinafe API",
    "version": "0.1.0",
    "description": "Compile OpenAPI specs and endpoint lists into agent-ready tool contracts."
  },
  "servers": [
    {
      "url": "https://alinafe.vercel.app"
    }
  ],
  "components": {
    "securitySchemes": {
      "alinafeApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-alinafe-key"
      }
    },
    "headers": {
      "RequestId": {
        "description": "Opaque request correlation ID. Send x-request-id to supply one, or Alinafe generates one.",
        "schema": {
          "type": "string",
          "minLength": 8,
          "maxLength": 128
        }
      },
      "AlinafeErrorCode": {
        "description": "Stable machine-readable error code mirrored in error.code.",
        "schema": {
          "type": "string"
        }
      },
      "IdempotentReplay": {
        "description": "true when a POST /v1/checkout response was replayed from an Idempotency-Key record.",
        "schema": {
          "type": "string",
          "enum": [
            "true",
            "false"
          ]
        }
      }
    },
    "schemas": {
      "Problem": {
        "type": "object",
        "required": [
          "type",
          "title",
          "status",
          "detail",
          "instance",
          "error"
        ],
        "additionalProperties": true,
        "properties": {
          "type": {
            "type": "string",
            "format": "uri"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "instance": {
            "type": "string"
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "requestId"
            ],
            "additionalProperties": true,
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "detail": {},
              "requestId": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "responses": {
      "Problem": {
        "description": "Problem details error response.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          },
          "x-alinafe-error-code": {
            "$ref": "#/components/headers/AlinafeErrorCode"
          }
        },
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "alinafeApiKey": []
    }
  ],
  "paths": {
    "/v1/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Check service health",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        },
        "security": []
      }
    },
    "/v1/openapi": {
      "get": {
        "operationId": "getOpenApi",
        "summary": "Get the Alinafe OpenAPI contract",
        "responses": {
          "200": {
            "description": "OpenAPI document",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        },
        "security": []
      }
    },
    "/v1/checkout": {
      "get": {
        "operationId": "getCheckoutPlans",
        "summary": "List paid checkout plans",
        "responses": {
          "200": {
            "description": "Checkout configuration and plans",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        },
        "security": []
      },
      "post": {
        "operationId": "createCheckout",
        "summary": "Create a Stripe Checkout Session for an Alinafe plan",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{8,128}$",
              "minLength": 8,
              "maxLength": 128
            },
            "description": "Optional retry key. Reusing the same key with the same email and plan returns the original Checkout Session."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "plan"
                ],
                "additionalProperties": false,
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "plan": {
                    "type": "string",
                    "enum": [
                      "pro",
                      "team",
                      "business",
                      "scale"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stripe Checkout URL and API-key claim URL",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              },
              "x-alinafe-idempotent-replay": {
                "$ref": "#/components/headers/IdempotentReplay"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        },
        "security": []
      }
    },
    "/v1/keys/claim": {
      "post": {
        "operationId": "claimApiKey",
        "summary": "Claim a paid API key after Stripe Checkout completes",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "sessionId",
                  "email"
                ],
                "additionalProperties": false,
                "properties": {
                  "sessionId": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "One-time API key response",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        },
        "security": []
      }
    },
    "/v1/account": {
      "get": {
        "operationId": "getAccount",
        "summary": "Get the current API-key account and usage",
        "responses": {
          "200": {
            "description": "Account profile and current monthly usage",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    },
    "/v1/billing/portal": {
      "post": {
        "operationId": "createBillingPortalSession",
        "summary": "Create a Stripe Billing Portal session for the current account",
        "responses": {
          "200": {
            "description": "Stripe Billing Portal redirect URL",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    },
    "/v1/keys/rotate": {
      "post": {
        "operationId": "rotateApiKey",
        "summary": "Rotate the current Stripe-issued API key",
        "responses": {
          "200": {
            "description": "New one-time API key response",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    },
    "/v1/keys/revoke": {
      "post": {
        "operationId": "revokeApiKey",
        "summary": "Revoke the current Stripe-issued API key",
        "responses": {
          "200": {
            "description": "Revoked account status",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    },
    "/v1/compile": {
      "post": {
        "operationId": "compileApi",
        "summary": "Compile an API into agent-ready tool contracts",
        "description": "Accepts an OpenAPI document or endpoint list and returns MCP-style tools, function tools, readiness scoring, and install templates.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true,
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "baseUrl": {
                    "type": "string"
                  },
                  "openapi": {
                    "type": "object"
                  },
                  "endpoints": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Compiled tool contracts",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    },
    "/v1/score": {
      "post": {
        "operationId": "scoreApi",
        "summary": "Score an API for agent readiness",
        "responses": {
          "200": {
            "description": "Readiness score and risk breakdown",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "Get usage for the current API key",
        "responses": {
          "200": {
            "description": "Current monthly usage",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Problem"
          }
        }
      }
    }
  }
}