{
  "openapi": "3.1.0",
  "info": {
    "title": "Monk API",
    "version": "2026-11-29",
    "description": "OpenAI- and Anthropic-compatible API for coding agents. Built for agents, controlled by humans. Docs for agents: https://monk.party/llms.txt",
    "contact": {
      "email": "support@monk.party"
    }
  },
  "servers": [
    {
      "url": "https://monk.party"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "summary": "OpenAI Chat Completions",
        "parameters": [
          {
            "name": "X-Monk-Agent",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "Agent ID. Usage, budgets and loop pauses are tracked per agent. Default: default."
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Retries with the same key and body replay the first result instead of running again (24h)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "enum": [
                      "monk",
                      "monk-fast",
                      "monk-coding",
                      "monk-free",
                      "monk-opus"
                    ]
                  },
                  "stream": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK (JSON, or text/event-stream when stream=true)"
          },
          "default": {
            "description": "Error. See https://monk.party/help/errors.html",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "summary": "Anthropic Messages (x-api-key or Bearer)",
        "parameters": [
          {
            "name": "X-Monk-Agent",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "Agent ID. Usage, budgets and loop pauses are tracked per agent. Default: default."
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Retries with the same key and body replay the first result instead of running again (24h)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "enum": [
                      "monk",
                      "monk-fast",
                      "monk-coding",
                      "monk-free",
                      "monk-opus"
                    ]
                  },
                  "stream": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK (JSON, or text/event-stream when stream=true)"
          },
          "default": {
            "description": "Error. See https://monk.party/help/errors.html",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/responses": {
      "post": {
        "summary": "OpenAI Responses",
        "parameters": [
          {
            "name": "X-Monk-Agent",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "Agent ID. Usage, budgets and loop pauses are tracked per agent. Default: default."
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Retries with the same key and body replay the first result instead of running again (24h)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "enum": [
                      "monk",
                      "monk-fast",
                      "monk-coding",
                      "monk-free",
                      "monk-opus"
                    ]
                  },
                  "stream": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK (JSON, or text/event-stream when stream=true)"
          },
          "default": {
            "description": "Error. See https://monk.party/help/errors.html",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "List models with live status (monk.status) and billing",
        "responses": {
          "200": {
            "description": "OK"
          },
          "default": {
            "description": "Error. See https://monk.party/help/errors.html",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/me": {
      "get": {
        "summary": "This key's plan, limits, usage, Opus wallet, budgets, per-agent usage and notices. Works even when the key is limited or expired.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "default": {
            "description": "Error. See https://monk.party/help/errors.html",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/me/budgets": {
      "post": {
        "summary": "Set your own daily budgets (lower than the platform limits). null removes one.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "daily_cost_cny": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "agents": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "daily_requests": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Same shape as GET /v1/me"
          },
          "default": {
            "description": "Error. See https://monk.party/help/errors.html",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/status": {
      "get": {
        "summary": "Per-model success rate over the last 15 minutes. No key needed.",
        "security": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "sk-monk-* key. /v1/messages also accepts x-api-key."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "message",
              "code"
            ],
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "code": {
                "type": "string",
                "enum": [
                  "invalid_api_key",
                  "key_expired",
                  "daily_quota_exceeded",
                  "budget_exceeded",
                  "agent_budget_exceeded",
                  "loop_detected",
                  "agent_cooldown",
                  "key_cooldown",
                  "rate_limit_exceeded",
                  "burst_limit",
                  "concurrency_limit",
                  "upstream_busy",
                  "upstream_quota",
                  "upstream_unavailable",
                  "upstream_error",
                  "model_not_available",
                  "model_not_found",
                  "context_length_exceeded",
                  "invalid_json",
                  "invalid_request",
                  "invalid_agent_id",
                  "insufficient_balance",
                  "daily_limit_exceeded",
                  "idempotency_key_reused",
                  "idempotency_in_progress",
                  "idempotency_replay_unavailable",
                  "client_closed"
                ]
              },
              "retryable": {
                "type": "boolean"
              },
              "action": {
                "type": "string",
                "enum": [
                  "fix_key",
                  "renew",
                  "wait_reset",
                  "fix_loop",
                  "wait",
                  "slow_down",
                  "retry_or_switch",
                  "fix_request",
                  "compact",
                  "top_up",
                  "use_new_key",
                  "retry"
                ]
              },
              "retry_after": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "suggested_model": {
                "type": "string"
              },
              "docs_url": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              }
            }
          }
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "overall": {
            "type": "string",
            "enum": [
              "ok",
              "degraded",
              "down"
            ]
          },
          "models": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "ok",
                    "degraded",
                    "down"
                  ]
                },
                "success_rate_15m": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "samples_15m": {
                  "type": "integer"
                },
                "breaker_open": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "Me": {
        "type": "object",
        "properties": {
          "key": {
            "type": "object"
          },
          "plan": {
            "type": "object"
          },
          "limits": {
            "type": "object"
          },
          "opus": {
            "type": "object"
          },
          "budgets": {
            "type": "object"
          },
          "agents": {
            "type": "object"
          },
          "models": {
            "type": "array"
          },
          "notices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                },
                "action_url": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}
