{
  "openapi": "3.1.0",
  "info": {
    "title": "ElephantPool — account, builder and host API",
    "version": "2026-11-30",
    "summary": "What a person, or an AI agent acting for them, can do on ElephantPool.",
    "description": "Read https://elephantpool.ai/agents.md first: it says which steps are the person's to decide. The inference API itself is OpenAI-compatible at https://app.elephantpool.ai/api/gateway/v1 and takes an API key (epk_…), not a session.",
    "contact": {
      "name": "ElephantPool",
      "email": "contact@elephantpool.ai",
      "url": "https://elephantpool.ai"
    },
    "termsOfService": "https://elephantpool.ai/legal/conditions"
  },
  "servers": [
    {
      "url": "https://elephantpool.ai"
    }
  ],
  "externalDocs": {
    "description": "Guide for AI agents",
    "url": "https://elephantpool.ai/agents.md"
  },
  "tags": [
    {
      "name": "session",
      "description": "Getting and keeping an agent session."
    },
    {
      "name": "account",
      "description": "The person's profile, sides and terms."
    },
    {
      "name": "builder",
      "description": "Plan, API keys, usage."
    },
    {
      "name": "host",
      "description": "Machines, earnings, payouts."
    },
    {
      "name": "public",
      "description": "No session needed."
    },
    {
      "name": "inference",
      "description": "OpenAI-compatible, with an API key."
    }
  ],
  "paths": {
    "/api/users/auth/agent/start": {
      "post": {
        "tags": [
          "session"
        ],
        "operationId": "startAgentAuthorization",
        "summary": "Ask to act for a person (RFC 8628 device authorization).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AgentStart"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Show the link and the code to the person.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentStartResult"
                }
              }
            }
          },
          "422": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "429": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/users/auth/agent/token": {
      "post": {
        "tags": [
          "session"
        ],
        "operationId": "agentToken",
        "summary": "Poll for the approval, or renew the access token.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/DeviceCodeGrant"
                  },
                  {
                    "$ref": "#/components/schemas/RefreshGrant"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentSession"
                }
              }
            }
          },
          "400": {
            "description": "Not yet, or never (RFC 8628 §3.5).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          },
          "429": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/users/auth/magic-link": {
      "post": {
        "tags": [
          "session"
        ],
        "operationId": "requestMagicLink",
        "summary": "Mail the person a one-time sign-in link (15 minutes).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "additionalProperties": false,
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "acquisition": {
                    "type": "object",
                    "description": "How the person found ElephantPool. An agent sets utm_source to \"agent\" and utm_medium to its name.",
                    "properties": {
                      "utm_source": {
                        "type": "string"
                      },
                      "utm_medium": {
                        "type": "string"
                      },
                      "utm_campaign": {
                        "type": "string"
                      },
                      "lang": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Always the same answer, whether or not an account exists."
          },
          "422": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "429": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/users/auth/magic-link/verify": {
      "get": {
        "tags": [
          "session"
        ],
        "operationId": "verifyMagicLink",
        "summary": "Exchange the token of the sign-in mail for a session.",
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          {
            "name": "agent",
            "in": "query",
            "required": false,
            "description": "The agent's name: makes it an agent session (listed in the person's settings, revocable).",
            "schema": {
              "type": "string",
              "maxLength": 60
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentSession"
                }
              }
            }
          },
          "401": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "422": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/users/me": {
      "get": {
        "tags": [
          "account"
        ],
        "operationId": "getMe",
        "summary": "The account.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "The account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          },
          "401": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "account"
        ],
        "operationId": "patchMe",
        "summary": "Change the profile, the sides, record the terms.",
        "description": "Recording `termsAccepted` is the person's decision (version 1.5). When the sides change the answer carries a new `token`: use it from then on.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UserPatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The account; `token` when the sides changed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          },
          "401": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "422": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/users/me/agents": {
      "get": {
        "tags": [
          "session"
        ],
        "operationId": "listAgents",
        "summary": "The agents connected to the account.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "The list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "agents": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ConnectedAgent"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/users/me/agents/{id}": {
      "delete": {
        "tags": [
          "session"
        ],
        "operationId": "revokeAgent",
        "summary": "End an agent session. An agent can only end its own.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked."
          },
          "403": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "404": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/gateway/keys": {
      "get": {
        "tags": [
          "builder"
        ],
        "operationId": "listKeys",
        "summary": "The API keys (never the secret).",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "The keys."
          }
        }
      },
      "post": {
        "tags": [
          "builder"
        ],
        "operationId": "createKey",
        "summary": "Create an API key. The secret is in this answer and nowhere else, ever.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 60
                  },
                  "monthly_cap_eur": {
                    "type": [
                      "number",
                      "null"
                    ],
                    "description": "Spend cap per calendar month; 20 when left out, null for none."
                  },
                  "region": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "eu",
                      null
                    ],
                    "description": "\"eu\": an EU-Sovereign key — machines located in the EU/EEA only."
                  },
                  "scope": {
                    "type": "string",
                    "enum": [
                      "any",
                      "own_machines"
                    ],
                    "description": "\"own_machines\": served only by the person's own machines, free (nothing billed, nothing paid); no cap, no region. Refused (409 NO_OWN_MACHINE) without a linked machine."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The key, with `key` (epk_ + 40 hex) shown once.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKeyCreated"
                }
              }
            }
          },
          "403": {
            "description": "TERMS_NOT_ACCEPTED: the terms of use are not accepted on the account, so no key. The person ticks them on the approval page, or the acceptance is recorded with PATCH /me (termsAccepted).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "409": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "422": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/gateway/keys/{id}": {
      "patch": {
        "tags": [
          "builder"
        ],
        "operationId": "updateKey",
        "summary": "Rename, change the cap or the region.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The key."
          }
        }
      },
      "delete": {
        "tags": [
          "builder"
        ],
        "operationId": "deleteKey",
        "summary": "Delete a key. Cannot be undone: confirm with the person.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted."
          }
        }
      }
    },
    "/api/gateway/billing": {
      "get": {
        "tags": [
          "builder"
        ],
        "operationId": "getBilling",
        "summary": "The plan, its month, its allowance, how it is paid.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Billing state."
          }
        }
      }
    },
    "/api/gateway/billing/plans": {
      "get": {
        "tags": [
          "builder"
        ],
        "operationId": "getBillingPlans",
        "summary": "The plans with this account's exact amounts, and the ways to pay.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Plans, packs, methods."
          }
        }
      }
    },
    "/api/gateway/billing/trial": {
      "get": {
        "tags": [
          "builder"
        ],
        "operationId": "getTrial",
        "summary": "Where the account stands with the card trial (also the `trial` block of /billing).",
        "description": "`trial` is null when the trial is not offered. `status`: available, waiting (card verified, credit added when the daily total has room), granted. `check`: the last card check (or the one named by `session_id`) and its `outcome`. `until`: when the offer of a new trial ends (null: no end); past it, `status` is no longer available.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "session_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^cs_"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The trial block."
          }
        }
      },
      "post": {
        "tags": [
          "builder"
        ],
        "operationId": "startTrial",
        "summary": "Create the Stripe page where the person verifies a card for the trial. Nothing is charged.",
        "description": "The card is the person's: ask first and hand them the `url`. Never enter or ask for card details. Once per card and per account; the credit is granted by Stripe's webhook, not by the return to the site. After the offer's `until`: 410 `TRIAL_OFFER_ENDED`.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "locale": {
                    "type": "string",
                    "enum": [
                      "en",
                      "fr",
                      "de",
                      "es",
                      "it",
                      "nl"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Where the person verifies a card.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "410": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "429": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/gateway/billing/checkout": {
      "post": {
        "tags": [
          "builder"
        ],
        "operationId": "createPlanCheckout",
        "summary": "Create the Stripe page where the person pays for a plan.",
        "description": "Paying is the person's: hand them the `url`. Never enter payment details.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "plan_id",
                  "method"
                ],
                "additionalProperties": false,
                "properties": {
                  "plan_id": {
                    "type": "string",
                    "examples": [
                      "p20"
                    ]
                  },
                  "method": {
                    "type": "string",
                    "description": "An id from `methods` of /billing/plans.",
                    "examples": [
                      "card"
                    ]
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "auto",
                      "manual"
                    ],
                    "description": "auto: a subscription that renews. manual: one month."
                  },
                  "locale": {
                    "type": "string",
                    "enum": [
                      "en",
                      "fr",
                      "de",
                      "es",
                      "it",
                      "nl"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Where the person pays.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "422": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/gateway/billing/change": {
      "post": {
        "tags": [
          "builder"
        ],
        "operationId": "changePlan",
        "summary": "Move a running subscription to another plan.",
        "description": "A higher plan is charged at once to the saved payment method and starts a new month today; a lower one applies at renewal. Only on the person's yes for that change, with its price.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "plan_id"
                ],
                "additionalProperties": false,
                "properties": {
                  "plan_id": {
                    "type": "string",
                    "examples": [
                      "p35"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Billing state, or `{ url }` when the person must act at Stripe."
          },
          "409": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "422": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/gateway/billing/resume": {
      "post": {
        "tags": [
          "builder"
        ],
        "operationId": "resumePlan",
        "summary": "Keep a subscription that was set to end: it renews, and is charged, again. Confirm with the person.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Billing state."
          },
          "409": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/gateway/billing/portal": {
      "post": {
        "tags": [
          "builder"
        ],
        "operationId": "billingPortal",
        "summary": "A Stripe page where the person changes their payment method.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "A link for the person."
          },
          "409": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/gateway/billing/cancel": {
      "post": {
        "tags": [
          "builder"
        ],
        "operationId": "cancelPlan",
        "summary": "Cancel the subscription (it runs to the end of the paid month). Confirm with the person.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Billing state."
          },
          "409": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/gateway/billing/invoices": {
      "get": {
        "tags": [
          "builder"
        ],
        "operationId": "listInvoices",
        "summary": "Invoices.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Invoices."
          }
        }
      }
    },
    "/api/gateway/usage": {
      "get": {
        "tags": [
          "builder"
        ],
        "operationId": "getUsage",
        "summary": "Tokens and cost, by day and by model.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Usage."
          }
        }
      }
    },
    "/api/gateway/usage/requests": {
      "get": {
        "tags": [
          "builder"
        ],
        "operationId": "listRequests",
        "summary": "The requests, one by one (never their content).",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Requests."
          }
        }
      }
    },
    "/api/gateway/earnings": {
      "get": {
        "tags": [
          "host"
        ],
        "operationId": "getEarnings",
        "summary": "What the person's machines were paid for.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Earnings."
          }
        }
      }
    },
    "/api/gateway/demand": {
      "get": {
        "tags": [
          "host"
        ],
        "operationId": "getDemand",
        "summary": "What builders asked for, and what each machine could have served.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Demand."
          }
        }
      }
    },
    "/api/gateway/payouts/connect/onboard": {
      "post": {
        "tags": [
          "host"
        ],
        "operationId": "payoutOnboard",
        "summary": "The Stripe page where the person sets up their payout account.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "A link for the person."
          }
        }
      }
    },
    "/api/gateway/payouts/connect/status": {
      "get": {
        "tags": [
          "host"
        ],
        "operationId": "payoutStatus",
        "summary": "Whether payouts are set up.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Status."
          }
        }
      }
    },
    "/api/hosts/link-codes": {
      "post": {
        "tags": [
          "host"
        ],
        "operationId": "createLinkCode",
        "summary": "A one-time code (15 minutes) for `mahout up --code`.",
        "description": "Carries the person's acceptance of the host terms (articles 8–9, version 1.5): ask them. The account needs the host side.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "accept_terms"
                ],
                "properties": {
                  "accept_terms": {
                    "type": "object",
                    "required": [
                      "version"
                    ],
                    "properties": {
                      "version": {
                        "type": "string",
                        "examples": [
                          "1.5"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The code.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "terms_version": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "409": {
            "description": "HOST_TERMS_OUTDATED: another version is in force; the answer names it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "422": {
            "description": "HOST_TERMS_NOT_ACCEPTED.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/hosts/hosts": {
      "get": {
        "tags": [
          "host"
        ],
        "operationId": "listHosts",
        "summary": "The person's machines and their state.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Machines."
          }
        }
      }
    },
    "/api/hosts/hosts/{id}": {
      "get": {
        "tags": [
          "host"
        ],
        "operationId": "getHost",
        "summary": "One machine.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The machine."
          },
          "404": {
            "description": "Refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "host"
        ],
        "operationId": "revokeHost",
        "summary": "Disconnect a machine. Confirm with the person.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Disconnected."
          }
        }
      }
    },
    "/api/hosts/{host_id}/settings": {
      "get": {
        "tags": [
          "host"
        ],
        "operationId": "getHostSettings",
        "summary": "A machine's settings (shared with `mahout config`).",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "host_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Settings."
          }
        }
      },
      "put": {
        "tags": [
          "host"
        ],
        "operationId": "putHostSettings",
        "summary": "Change a machine's settings.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "host_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Settings."
          }
        }
      }
    },
    "/api/gateway/v1/public/models": {
      "get": {
        "tags": [
          "public"
        ],
        "operationId": "publicModels",
        "summary": "Every model: prices per million tokens, context, builds, and how many machines serve it now (`hosts_live`).",
        "responses": {
          "200": {
            "description": "The catalogue."
          }
        }
      }
    },
    "/api/gateway/v1/public/plans": {
      "get": {
        "tags": [
          "public"
        ],
        "operationId": "publicPlans",
        "summary": "The monthly plans, the packs, the ways to pay.",
        "responses": {
          "200": {
            "description": "Plans."
          }
        }
      }
    },
    "/api/gateway/v1/public/fleet": {
      "get": {
        "tags": [
          "public"
        ],
        "operationId": "publicFleet",
        "summary": "The machines connected in the last 24 hours, anonymised, and per model the work of the last 24 hours (`requests_24h`, `output_tokens_24h`, `unserved_24h`). Its `hosts` counts machines that can serve a model, serving or not; `hosts_live` of the models list counts those serving now.",
        "responses": {
          "200": {
            "description": "Fleet."
          }
        }
      }
    },
    "/api/gateway/v1/agent": {
      "get": {
        "tags": [
          "public"
        ],
        "operationId": "mahoutRelease",
        "summary": "The signed manifest of the current mahout release (version, artifacts, sha256).",
        "responses": {
          "200": {
            "description": "Manifest."
          }
        }
      }
    },
    "/api/gateway/v1/chat/completions": {
      "post": {
        "tags": [
          "inference"
        ],
        "operationId": "chatCompletions",
        "summary": "OpenAI-compatible chat completions.",
        "description": "Use https://app.elephantpool.ai/api/gateway/v1 as the base URL of any OpenAI SDK. `X-ElephantPool-Require: region:eu` keeps a request on machines located in the EU/EEA. Function calling works on the models whose `capabilities` (`/api/gateway/v1/public/models`) include `tool-use`. Message roles: system, user, assistant, tool (not developer); content parts: text and image_url (a data: URL). Fields not listed here are dropped, not refused. This is the only inference route besides `GET /models`: there is no /responses, /completions, /embeddings or Anthropic /messages.",
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "role"
                      ],
                      "properties": {
                        "role": {
                          "enum": [
                            "system",
                            "user",
                            "assistant",
                            "tool"
                          ]
                        },
                        "content": {},
                        "tool_calls": {
                          "type": "array"
                        },
                        "tool_call_id": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "stream": {
                    "type": "boolean"
                  },
                  "max_tokens": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 131072
                  },
                  "temperature": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 2
                  },
                  "tools": {
                    "type": "array",
                    "maxItems": 128,
                    "items": {
                      "type": "object"
                    },
                    "description": "OpenAI function definitions: `{\"type\":\"function\",\"function\":{\"name\",\"description\",\"parameters\"}}`."
                  },
                  "tool_choice": {
                    "description": "`none`, `auto`, `required`, or `{\"type\":\"function\",\"function\":{\"name\":\"…\"}}`."
                  },
                  "parallel_tool_calls": {
                    "type": "boolean"
                  },
                  "reasoning_effort": {
                    "type": "string",
                    "description": "On the models that reason."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A completion, or a server-sent event stream."
          },
          "401": {
            "description": "OpenAI-style error."
          },
          "402": {
            "description": "insufficient_credits: no plan running, or its allowance is used up."
          },
          "503": {
            "description": "no_eligible_host: no connected machine can serve this request now."
          }
        }
      }
    },
    "/api/gateway/v1/models": {
      "get": {
        "tags": [
          "inference"
        ],
        "operationId": "listModels",
        "summary": "The model ids, OpenAI format.",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Models."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "session": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "The access_token of an agent session (15 minutes; renew with the refresh token)."
      },
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "A builder API key: epk_ + 40 hex."
      }
    },
    "schemas": {
      "ServiceError": {
        "type": "object",
        "properties": {
          "errors": {
            "type": "object",
            "properties": {
              "msg": {
                "type": "string",
                "examples": [
                  "AGENT_NOT_ALLOWED"
                ]
              }
            }
          }
        }
      },
      "OAuthError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "authorization_pending",
              "slow_down",
              "access_denied",
              "expired_token",
              "invalid_grant",
              "invalid_request",
              "unsupported_grant_type"
            ]
          },
          "error_description": {
            "type": "string"
          }
        }
      },
      "AgentStart": {
        "type": "object",
        "required": [
          "client_name"
        ],
        "additionalProperties": false,
        "properties": {
          "client_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60,
            "description": "The name the person knows the agent by. Letters, digits, spaces and . _ - ( ) / + only."
          },
          "intent": {
            "type": "string",
            "enum": [
              "host",
              "builder",
              "both"
            ]
          },
          "login_hint": {
            "type": "string",
            "format": "email",
            "maxLength": 254,
            "description": "The address the person signs in with, if they told the agent. The approval page fills it in and warns when another account is signed in; nothing is mailed to it, no account is made with it. Never put it in a URL."
          },
          "profile": {
            "type": "object",
            "additionalProperties": false,
            "description": "Only what the person told the agent. Shown to them before they approve.",
            "properties": {
              "name": {
                "type": "string",
                "maxLength": 120
              },
              "country": {
                "type": "string",
                "maxLength": 60
              },
              "building": {
                "type": "string",
                "maxLength": 500
              }
            }
          }
        }
      },
      "AgentStartResult": {
        "type": "object",
        "properties": {
          "device_code": {
            "type": "string"
          },
          "user_code": {
            "type": "string",
            "examples": [
              "WDJB-MJHT"
            ]
          },
          "verification_uri": {
            "type": "string",
            "format": "uri"
          },
          "verification_uri_complete": {
            "type": "string",
            "format": "uri"
          },
          "expires_in": {
            "type": "integer",
            "examples": [
              900
            ]
          },
          "interval": {
            "type": "integer",
            "examples": [
              5
            ]
          }
        }
      },
      "DeviceCodeGrant": {
        "type": "object",
        "required": [
          "grant_type",
          "device_code"
        ],
        "properties": {
          "grant_type": {
            "const": "urn:ietf:params:oauth:grant-type:device_code"
          },
          "device_code": {
            "type": "string"
          }
        }
      },
      "RefreshGrant": {
        "type": "object",
        "required": [
          "grant_type",
          "refresh_token"
        ],
        "properties": {
          "grant_type": {
            "const": "refresh_token"
          },
          "refresh_token": {
            "type": "string",
            "pattern": "^epr_[0-9a-f]{48}$"
          }
        }
      },
      "AgentSession": {
        "type": "object",
        "properties": {
          "access_token": {
            "type": "string"
          },
          "token": {
            "type": "string",
            "description": "The same JWT as access_token (the name the sign-in link has always used). A secret too."
          },
          "token_type": {
            "const": "Bearer"
          },
          "expires_in": {
            "type": "integer"
          },
          "refresh_token": {
            "type": "string"
          },
          "refresh_expires_in": {
            "type": "integer"
          },
          "agent": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "user": {
            "$ref": "#/components/schemas/User"
          },
          "needs": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "persona",
                "terms"
              ]
            },
            "description": "What the account still lacks. Empty when the person approved in the browser."
          }
        }
      },
      "ConnectedAgent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "via": {
            "type": "string",
            "enum": [
              "device",
              "magic_link"
            ]
          },
          "connected_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_used_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "current": {
            "type": "boolean"
          }
        }
      },
      "User": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "name": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "locale": {
            "type": "string"
          },
          "personas": {
            "type": "object",
            "properties": {
              "builder": {
                "type": "boolean"
              },
              "host": {
                "type": "boolean"
              }
            }
          },
          "termsAcceptedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "termsVersion": {
            "type": [
              "string",
              "null"
            ]
          },
          "token": {
            "type": "string",
            "description": "Only in the answer to a PATCH that changed the sides."
          }
        }
      },
      "UserPatch": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "company": {
            "type": "string",
            "maxLength": 120
          },
          "country": {
            "type": "string",
            "maxLength": 60
          },
          "locale": {
            "type": "string",
            "enum": [
              "en",
              "fr",
              "de",
              "es",
              "it",
              "nl"
            ]
          },
          "personas": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "builder": {
                "type": "boolean"
              },
              "host": {
                "type": "boolean"
              }
            }
          },
          "termsAccepted": {
            "type": "object",
            "required": [
              "version"
            ],
            "properties": {
              "version": {
                "type": "string",
                "examples": [
                  "1.5"
                ]
              }
            }
          },
          "news_consent": {
            "type": "object",
            "required": [
              "given",
              "version"
            ],
            "properties": {
              "given": {
                "type": "boolean"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "profile": {
            "type": "object",
            "properties": {
              "building": {
                "type": "string",
                "maxLength": 500
              }
            }
          }
        }
      },
      "ApiKeyCreated": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "key": {
            "type": "string",
            "pattern": "^epk_[0-9a-f]{40}$"
          },
          "last4": {
            "type": "string"
          },
          "monthly_cap_eur": {
            "type": [
              "number",
              "null"
            ]
          },
          "region": {
            "type": [
              "string",
              "null"
            ]
          },
          "scope": {
            "type": "string",
            "enum": [
              "any",
              "own_machines"
            ]
          }
        }
      }
    }
  }
}
