{
  "openapi": "3.0.3",
  "info": {
    "title": "Ravi API",
    "version": "1.0.0",
    "description": "Identity provider for AI agents \u2014 provisioned phone numbers, email addresses, TOTP, OTP extraction, and E2E-encrypted passwords and secrets."
  },
  "paths": {
    "/api/auth/device/": {
      "post": {
        "operationId": "auth_device_create",
        "description": "Generate a new device code.",
        "tags": [
          "Device Auth"
        ],
        "security": [
          {}
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceCodeResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/api/auth/device/token/": {
      "post": {
        "operationId": "auth_device_token_create",
        "description": "Check authorization status and return tokens if ready.",
        "tags": [
          "Device Auth"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeviceTokenRequestRequest"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/DeviceTokenRequestRequest"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/DeviceTokenRequestRequest"
              }
            }
          },
          "required": true
        },
        "security": [
          {}
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceTokenSuccess"
                }
              }
            },
            "description": ""
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceTokenErrorResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DeviceCodeResponse": {
        "type": "object",
        "description": "Serializer for device code response.",
        "properties": {
          "device_code": {
            "type": "string",
            "description": "Code for client polling"
          },
          "user_code": {
            "type": "string",
            "description": "Code for user to enter"
          },
          "verification_uri": {
            "type": "string",
            "format": "uri",
            "description": "URL for user to visit"
          },
          "expires_in": {
            "type": "integer",
            "description": "Seconds until expiration"
          },
          "interval": {
            "type": "integer",
            "description": "Polling interval in seconds"
          }
        },
        "required": [
          "device_code",
          "expires_in",
          "interval",
          "user_code",
          "verification_uri"
        ]
      },
      "DeviceTokenErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "error_description": {
            "type": "string"
          }
        },
        "required": [
          "error",
          "error_description"
        ]
      },
      "DeviceTokenRequestRequest": {
        "type": "object",
        "description": "Serializer for device token polling request.",
        "properties": {
          "device_code": {
            "type": "string",
            "minLength": 1,
            "description": "Device code from initial request"
          },
          "wait": {
            "type": "boolean",
            "default": false,
            "description": "Long-poll: block up to 120s until authorized or expired"
          }
        },
        "required": [
          "device_code"
        ]
      },
      "DeviceTokenSuccess": {
        "type": "object",
        "description": "Serializer for successful token response.\n\nShape varies by identity count:\n- 1 identity (signup): includes ``identity_key`` + ``identity`` dict\n- 0 or >1 identities (login): includes ``identities`` list, no auto-created key",
        "properties": {
          "access": {
            "type": "string",
            "description": "JWT access token"
          },
          "refresh": {
            "type": "string",
            "description": "JWT refresh token"
          },
          "management_key": {
            "type": "string",
            "description": "Management API key (ravi_mgmt_...)"
          },
          "user": {
            "type": "object",
            "additionalProperties": {},
            "description": "User information"
          },
          "identity_key": {
            "type": "string",
            "description": "Identity API key (ravi_id_...) \u2014 only present for single-identity (signup) flows"
          },
          "identity": {
            "type": "object",
            "additionalProperties": {},
            "description": "Default identity info (uuid, name, email) \u2014 only present for signup"
          },
          "identities": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": {}
            },
            "description": "All user identities \u2014 present for login (>1 or 0 identities)"
          }
        },
        "required": [
          "access",
          "management_key",
          "refresh",
          "user"
        ]
      }
    }
  }
}
