{
  "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": {
      "post": {
        "tags": [
          "Sub-API Keys"
        ],
        "summary": "Create Sub-API Key",
        "description": "Creates a new sub-API key scoped under the authenticated admin key. The sub-key inherits the admin's credit pool and can be further restricted by allowed models and a per-key credit limit.",
        "operationId": "create_sub_key",
        "parameters": [
          {
            "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 with full access. Sub-keys created by this key inherit its credit pool."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSubKeyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Sub-API key created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateSubKeyResponse"
                },
                "example": {
                  "status": "succeeded",
                  "data": {
                    "key_id": "71775d2e-fbcc-4ef4-aa30-8aaeb82062c0",
                    "value": "acme-v2-eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
                    "display": "acme-v2-eyJh...c0eQ",
                    "admin_user_id": "95ce9361-447f-4ec0-a698-764c2a2d15b9",
                    "description": "Partner integration key",
                    "allowed_models": [
                      "meta-llama/Llama-3.3-70B-Instruct"
                    ],
                    "credit_limit": 10.0,
                    "credit_refresh_cycle": "monthly",
                    "expires_at": "2026-08-20T00:00:00"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized \u2014 invalid or missing API key"
          },
          "403": {
            "description": "Forbidden \u2014 the provided key is a sub-key and cannot create further sub-keys"
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "oauth2",
        "flows": {}
      }
    },
    "schemas": {
      "CreateSubKeyRequest": {
        "type": "object",
        "required": [
          "description"
        ],
        "title": "CreateSubKeyRequest",
        "properties": {
          "description": {
            "type": "string",
            "title": "Description",
            "description": "A human-readable label for the sub-key."
          },
          "scopes": {
            "anyOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              {
                "type": "null"
              }
            ],
            "title": "Scopes",
            "description": "Access scopes. Defaults to [\"intelligence\"] if omitted.",
            "default": null
          },
          "allowed_models": {
            "anyOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "List of model identifiers this sub-key is permitted to use. If omitted, all models available to the admin are allowed."
              },
              {
                "type": "null"
              }
            ],
            "title": "Allowed Models",
            "default": null
          },
          "credit_limit": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0
              },
              {
                "type": "null"
              }
            ],
            "title": "Credit Limit",
            "description": "Maximum credits (in IO Intelligence credits) the sub-key may consume per refresh cycle. Null means no per-key limit \u2014 the admin's overall balance applies.",
            "default": null
          },
          "credit_refresh_cycle": {
            "type": "string",
            "enum": [
              "8h",
              "daily",
              "weekly",
              "monthly"
            ],
            "title": "Credit Refresh Cycle",
            "description": "How often the sub-key's credit_used counter resets. Defaults to \"monthly\".",
            "default": "monthly"
          },
          "expires_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "string",
                "enum": [
                  "never"
                ]
              },
              {
                "type": "null"
              }
            ],
            "title": "Expires At",
            "description": "Expiry date-time for the key. Pass \"never\" for a non-expiring key. Defaults to 180 days from creation if omitted.",
            "default": null
          },
          "key_prefix": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 2,
                "maxLength": 8,
                "pattern": "^[a-z][a-z0-9-]*[a-z0-9]$",
                "description": "Custom lowercase slug prepended to the key (e.g. \"acme\" produces \"acme-v2-...\"). Must be 2\u20138 lowercase alphanumeric characters with optional internal hyphens. Cannot start with \"io\" (reserved) or contain version markers such as \"-v2\"."
              },
              {
                "type": "null"
              }
            ],
            "title": "Key Prefix",
            "description": "Optional prefix slug for the generated key. Defaults to the standard \"io-v2\" prefix when omitted.",
            "default": null
          }
        }
      },
      "SubKeyCreated": {
        "type": "object",
        "title": "SubKeyCreated",
        "properties": {
          "key_id": {
            "type": "string",
            "format": "uuid",
            "title": "Key ID"
          },
          "value": {
            "type": "string",
            "title": "Value",
            "description": "The full API key string. This is shown only once \u2014 store it securely."
          },
          "display": {
            "type": "string",
            "title": "Display",
            "description": "A truncated, safe-to-display version of the key (e.g. \"acme-v2-eyJh...c0eQ\")."
          },
          "admin_user_id": {
            "type": "string",
            "format": "uuid",
            "title": "Admin User ID"
          },
          "description": {
            "type": "string",
            "title": "Description"
          },
          "allowed_models": {
            "anyOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              {
                "type": "null"
              }
            ],
            "title": "Allowed Models"
          },
          "credit_limit": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Credit Limit"
          },
          "credit_refresh_cycle": {
            "type": "string",
            "title": "Credit Refresh Cycle"
          },
          "expires_at": {
            "type": "string",
            "title": "Expires At"
          }
        }
      },
      "CreateSubKeyResponse": {
        "type": "object",
        "title": "CreateSubKeyResponse",
        "properties": {
          "status": {
            "type": "string",
            "example": "succeeded"
          },
          "data": {
            "$ref": "#/components/schemas/SubKeyCreated"
          }
        }
      },
      "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"
      }
    }
  }
}