{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/mensageiro-ai/json-schema/mensageiro-ai-key-create-schema.json",
  "title": "KeyCreate",
  "x-generated": "2026-11-17",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/mensageiro-ai-openapi.json#/components/schemas/KeyCreate",
  "type": "object",
  "required": [
    "name"
  ],
  "properties": {
    "name": {
      "type": "string",
      "description": "1 to 64 characters."
    },
    "environment": {
      "type": "string",
      "enum": [
        "live",
        "test"
      ],
      "description": "live unless set."
    },
    "format": {
      "type": "string",
      "enum": [
        "native",
        "claude",
        "gpt",
        "gemini",
        "deepseek",
        "glm"
      ],
      "description": "The shape the key is minted in: native (sk-<brand>-…) unless set; claude (sk-ant-…), gpt (sk-proj-…), gemini (AIza…), deepseek (sk-<hex>, 35 chars) or glm (id.secret) for tools that check the prefix. Every format works on every model."
    },
    "allowed_models": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "Up to 100 model ids; the key may call nothing else."
    },
    "allowed_ips": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "Up to 50 IPv4/IPv6 addresses or CIDRs (1.2.3.4, 10.0.0.0/8, 2001:db8::/32); the key answers 403 ip_not_allowed from anywhere else."
    },
    "rpm": {
      "type": "integer",
      "description": "Requests per minute, 1 to 600. Default 200; higher on request."
    },
    "tpm": {
      "type": "integer",
      "description": "Tokens per minute, 1 to 50,000,000."
    },
    "monthly_cap_usd": {
      "type": "number",
      "description": "Dollars the key may spend per spend_limit_period (a UTC month unless set); the counter restarts at the start of each period."
    },
    "spend_limit_period": {
      "type": "string",
      "enum": [
        "daily",
        "weekly",
        "monthly"
      ],
      "description": "monthly unless set. daily resets at 00:00 UTC, weekly at Monday 00:00 UTC."
    },
    "concurrency": {
      "type": "integer",
      "description": "Requests this key may have in flight at once, 1 to 50; higher on request. The console's name concurrency_limit is accepted too."
    },
    "budget_usd": {
      "type": "number",
      "description": "The key's own prepaid budget in dollars, carved out of your balance. Once used up the key gets 402 key_budget_exhausted until it is raised."
    },
    "expires_at": {
      "type": "integer",
      "description": "Unix milliseconds, in the future."
    },
    "routing": {
      "type": "string",
      "enum": [
        "cheapest",
        "fastest",
        "throughput"
      ]
    },
    "retain_bodies": {
      "type": "boolean",
      "description": "Keep request bodies 7 days for replay."
    },
    "session_max_requests": {
      "type": "integer",
      "description": "Requests one session may make per sliding hour, 1 to 100,000."
    },
    "session_max_spend_usd": {
      "type": "number",
      "description": "Dollars one session may be charged per UTC day. The console's session_max_spend_micro is accepted too."
    },
    "user_budget_usd": {
      "type": "number",
      "description": "Dollars one end user (x-customer-id, else the `user` field) may be charged per user_budget_period. The console's user_budget_micro is accepted too. Past it that user gets 402 user_budget_reached."
    },
    "user_budget_period": {
      "type": "string",
      "enum": [
        "daily",
        "weekly",
        "monthly"
      ],
      "description": "monthly unless set."
    },
    "loop_guard": {
      "type": "boolean",
      "description": "Refuse a session's repeated identical tool call or body (more than 5 in 10 minutes)."
    },
    "redact": {
      "type": "string",
      "enum": [
        "off",
        "secrets",
        "secrets_pii"
      ],
      "description": "Default off."
    },
    "fallback_models": {
      "$ref": "#/$defs/FallbackModels"
    },
    "response_cache_ttl": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Response cache on by default, for this many seconds (60 to 86,400); null or 0 for off."
    },
    "context_overflow": {
      "type": "string",
      "enum": [
        "error",
        "middle-out"
      ],
      "description": "error unless set."
    },
    "scope": {
      "type": "string",
      "enum": [
        "api"
      ],
      "description": "Only api here; an admin key is created in the console."
    },
    "guardrails": {
      "oneOf": [
        {
          "$ref": "#/$defs/Guardrails"
        },
        {
          "type": "null"
        }
      ],
      "description": "The key's own guardrails; null for none. The organization default (GET /v1/guardrails) layers under them."
    }
  },
  "$defs": {
    "BlockedPattern": {
      "type": "object",
      "required": [
        "pattern"
      ],
      "properties": {
        "pattern": {
          "type": "string",
          "description": "A JavaScript regular expression, up to 512 characters. Backreferences, lookaround and a repeated group that holds a repeat or alternatives are refused."
        },
        "flags": {
          "type": "string",
          "description": "Any of i, m, s, u. i unless set.",
          "pattern": "^[imsu]{0,4}$"
        },
        "action": {
          "type": "string",
          "enum": [
            "block",
            "flag"
          ],
          "description": "block unless set."
        },
        "name": {
          "type": [
            "string",
            "null"
          ],
          "description": "Named in the error message instead of the pattern's position."
        }
      }
    },
    "FallbackModels": {
      "type": "array",
      "maxItems": 5,
      "items": {
        "type": "string"
      },
      "description": "Up to 5 model ids or aliases tried in order after `model` once every route of the one before has failed before a byte was sent. Each is billed at its own price when it answers; the key's allowlist applies to each."
    },
    "Guardrails": {
      "type": "object",
      "description": "Opt-in checks on your own traffic. Nothing applies unless set. A blocked request answers 400 guardrail_blocked before any model is asked and costs nothing; a flagged one carries `x-uplink-guardrail: flagged`; a stripped tool call `x-uplink-guardrail: tool_call_stripped`.",
      "properties": {
        "blocked_patterns": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/BlockedPattern"
          },
          "description": "Up to 50. Checked against the prompt's system, user and tool text (not earlier assistant turns). A string is shorthand for { pattern, action: block, flags: i }."
        },
        "prompt_injection": {
          "type": "string",
          "enum": [
            "off",
            "flag",
            "block"
          ],
          "description": "A local heuristic detector, no model call: known override and jailbreak phrasings, chat-template and role markers inside user or tool text, instructions aimed at the model inside tool results, invisible Unicode tag characters. It matches wording: paraphrases, other languages and encoded payloads pass, and text quoting an attack is flagged like one."
        },
        "tool_policy": {
          "oneOf": [
            {
              "$ref": "#/$defs/ToolPolicy"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "ToolPolicy": {
      "type": "object",
      "properties": {
        "allow": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string"
          },
          "description": "Only these tools; null for every tool not denied. A trailing * matches a prefix."
        },
        "deny": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Never these: function names, server tools (web_search) and /mcp/org names (github__delete_*). Their declarations are removed before the request is forwarded, a tool_choice forcing one is refused, and a call to one in an answer is stripped."
        }
      }
    }
  }
}