{
  "openapi": "3.1.0",
  "info": {
    "title": "GetCourier API",
    "version": "0.1.0-alpha",
    "description": "Agent identity infrastructure. One call provisions an inbox, cryptographic keypair, scoped token, and Lightning payment terms. North-star metric: TTFI, time to first inbox."
  },
  "servers": [
    {
      "url": "https://getcourier.dev"
    }
  ],
  "paths": {
    "/inbox": {
      "post": {
        "summary": "Provision an agent identity (authenticated / BYOD \u2014 requires a write token)",
        "description": "Authenticated provisioning with terms + Lightning invoice. Returns 401 without a valid write token. For the public one-call demo, use POST /alias.",
        "operationId": "createInbox",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateInboxRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Provisioned identity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateInboxResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required \u2014 use POST /alias for the public demo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/inbox/{inbox_id}/messages": {
      "get": {
        "summary": "Read inbox messages with extracted codes and links",
        "operationId": "listInboxMessages",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "inbox_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Messages",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "messages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    }
                  },
                  "required": [
                    "messages"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Token does not own this inbox (NOT_OWNER)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Read messages for an inbox. The holder of this inbox's read token sees extracted codes IN FULL. Any other token -> 403 NOT_OWNER; no token -> 401."
      }
    },
    "/alias": {
      "post": {
        "summary": "Provision an agent identity (public one-call demo, no signup)",
        "operationId": "createAlias",
        "description": "Public provisioning. No auth, no body required. Returns an inbox, an Ed25519 identity, and an inbox-scoped read_token (shown once). Rate-limited per client.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAliasRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Identity provisioned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateAliasResponse"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited \u2014 back off retry_after_seconds and retry",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RateLimitError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "CreateInboxRequest": {
        "type": "object",
        "properties": {
          "agent": {
            "type": "string",
            "examples": [
              "build-bot-7"
            ]
          },
          "terms_accepted": {
            "type": "boolean",
            "const": true
          },
          "terms_version": {
            "type": "string",
            "examples": [
              "2026-07-26"
            ]
          }
        },
        "required": [
          "agent",
          "terms_accepted",
          "terms_version"
        ]
      },
      "CreateInboxResponse": {
        "type": "object",
        "properties": {
          "inbox": {
            "type": "string",
            "examples": [
              "build-bot-7@getcourier.dev"
            ]
          },
          "inbox_id": {
            "type": "string",
            "examples": [
              "build-bot-7"
            ]
          },
          "public_key": {
            "type": "string",
            "examples": [
              "ed25519:9c7b...a91f"
            ]
          },
          "read_token_scope": {
            "type": "string",
            "examples": [
              "inbox:read:build-bot-7"
            ]
          },
          "read_token": {
            "type": "string"
          },
          "invoice": {
            "$ref": "#/components/schemas/Invoice"
          }
        },
        "required": [
          "inbox",
          "inbox_id",
          "public_key",
          "read_token_scope",
          "invoice"
        ]
      },
      "Invoice": {
        "type": "object",
        "properties": {
          "network": {
            "type": "string",
            "const": "lightning"
          },
          "amount_sats": {
            "type": "integer",
            "minimum": 0
          },
          "next_inbox_sats": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "network",
          "amount_sats"
        ]
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "subject": {
            "type": "string"
          },
          "classification": {
            "type": "string",
            "examples": [
              "verification_code"
            ]
          },
          "codes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string"
                },
                "code": {
                  "type": "string",
                  "description": "Full extracted code for the inbox read-token holder"
                }
              }
            }
          },
          "links": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "received_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "from",
          "to",
          "subject",
          "codes",
          "links",
          "received_at"
        ]
      },
      "CreateAliasRequest": {
        "type": "object",
        "properties": {
          "purpose": {
            "type": "string",
            "examples": [
              "agent-demo"
            ]
          },
          "agent": {
            "type": "string",
            "examples": [
              "build-bot-7"
            ]
          },
          "service": {
            "type": "string",
            "examples": [
              "generic"
            ]
          }
        }
      },
      "CreateAliasResponse": {
        "type": "object",
        "required": [
          "success",
          "alias",
          "read_token"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "const": true
          },
          "read_token": {
            "type": "string",
            "description": "Inbox-scoped, shown once"
          },
          "alias": {
            "type": "object",
            "properties": {
              "alias": {
                "type": "string"
              },
              "inbox_id": {
                "type": "string"
              },
              "read_token": {
                "type": "string"
              },
              "purpose": {
                "type": "string"
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "identity": {
            "type": "object",
            "properties": {
              "did": {
                "type": "string",
                "examples": [
                  "did:courier:default:6818378494c9ef0f"
                ]
              },
              "public_key": {
                "type": "object"
              },
              "fingerprint": {
                "type": "string"
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "boolean",
            "const": true
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "retryable": {
            "type": "boolean"
          }
        }
      },
      "RateLimitError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "boolean",
            "const": true
          },
          "code": {
            "type": "string",
            "const": "RATE_LIMITED"
          },
          "message": {
            "type": "string"
          },
          "retryable": {
            "type": "boolean",
            "const": true
          },
          "retry_after_seconds": {
            "type": "integer",
            "examples": [
              10
            ]
          }
        }
      }
    }
  }
}