{
  "openapi": "3.1.0",
  "info": {
    "title": "IO Intelligence",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.io.solutions"
    }
  ],
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/v1/api-keys/sub-keys/{key_id}/usage": {
      "get": {
        "tags": [
          "Sub-API Keys"
        ],
        "summary": "Get Sub-Key Usage",
        "description": "Returns the credit status for a specific sub-key: how much has been consumed in the current billing period, the configured limit, and the remaining allowance.",
        "operationId": "get_key_usage",
        "parameters": [
          {
            "name": "key_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid",
              "title": "Key ID"
            },
            "description": "UUID of the sub-key to inspect."
          },
          {
            "name": "x-api-key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Admin API key (io.net Intelligence)",
              "title": "X-Api-Key"
            },
            "description": "Admin API key that owns the sub-key."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KeyUsageResponse"
                },
                "example": {
                  "status": "succeeded",
                  "data": {
                    "key_id": "71775d2e-fbcc-4ef4-aa30-8aaeb82062c0",
                    "credit_used": 1.234,
                    "credit_limit": 10.0,
                    "remaining_credit": 8.766,
                    "credit_refresh_cycle": "monthly"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized \u2014 invalid or missing API key"
          },
          "404": {
            "description": "Sub-API key not found or not owned by this admin"
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "oauth2",
        "flows": {}
      }
    },
    "schemas": {
      "KeyUsageData": {
        "type": "object",
        "title": "KeyUsageData",
        "properties": {
          "key_id": {
            "type": "string",
            "format": "uuid",
            "title": "Key ID"
          },
          "credit_used": {
            "type": "number",
            "title": "Credit Used",
            "description": "Credits consumed in the current billing period."
          },
          "credit_limit": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Credit Limit",
            "description": "Maximum credits allowed per cycle. Null if no per-key limit is set."
          },
          "remaining_credit": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Remaining Credit",
            "description": "Credits remaining before the key is blocked. Null if no limit is configured."
          },
          "credit_refresh_cycle": {
            "type": "string",
            "enum": [
              "8h",
              "daily",
              "weekly",
              "monthly"
            ],
            "title": "Credit Refresh Cycle"
          }
        }
      },
      "KeyUsageResponse": {
        "type": "object",
        "title": "KeyUsageResponse",
        "properties": {
          "status": {
            "type": "string",
            "example": "succeeded"
          },
          "data": {
            "$ref": "#/components/schemas/KeyUsageData"
          }
        }
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      }
    }
  }
}