{
  "openapi": "3.1.0",
  "info": {
    "title": "Devura API - Developers Aura",
    "version": "1.0.0",
    "description": "Paid model gateway and quota-controlled free agent. Text Chat Completions and function tools. No provider credentials are exposed."
  },
  "servers": [
    {
      "url": "https://api.devura.me/v1",
      "description": "Paid model API"
    },
    {
      "url": "https://agent.devura.me/v1",
      "description": "Free agent; use model devura-agent"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Devura dvk_ API key or dvr_ device token"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "code": {
                "type": "string"
              }
            }
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "ChatRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "Public Devura model ID, or devura-agent on the free agent service."
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "type": "object",
              "required": [
                "role"
              ],
              "properties": {
                "role": {
                  "enum": [
                    "system",
                    "developer",
                    "user",
                    "assistant",
                    "tool"
                  ]
                },
                "content": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "tool_calls": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                },
                "tool_call_id": {
                  "type": "string"
                }
              }
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 32768
          },
          "max_completion_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 32768
          },
          "stream": {
            "type": "boolean",
            "default": false,
            "description": "Buffered SSE compatibility: chunks are emitted after upstream completion."
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2
          },
          "top_p": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "tools": {
            "type": "array",
            "maxItems": 32,
            "items": {
              "type": "object"
            }
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string",
                "enum": [
                  "auto",
                  "none",
                  "required"
                ]
              },
              {
                "type": "object"
              }
            ]
          },
          "response_format": {
            "type": "object"
          }
        }
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "chat.completion"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens": {
                "type": "integer"
              },
              "completion_tokens": {
                "type": "integer"
              },
              "total_tokens": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/models": {
      "get": {
        "operationId": "listModels",
        "summary": "Discover public model IDs, prices and limits",
        "responses": {
          "200": {
            "description": "Model catalog"
          },
          "401": {
            "description": "Invalid API key or account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Generate text or function tool calls",
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Reuse the same UUID and identical payload for safe retries."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion; SSE is buffered when stream=true",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key or account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient wallet credit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency conflict or reconciliation required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Input too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Quota or rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Upstream failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service disabled or unavailable capacity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/usage": {
      "get": {
        "operationId": "getQuotaUsage",
        "summary": "Read caller rolling quotas and usage",
        "responses": {
          "200": {
            "description": "Caller quota limits and usage"
          },
          "401": {
            "description": "Invalid API key or account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/requests/{id}": {
      "get": {
        "operationId": "getRequestStatus",
        "summary": "Read a request owned by the caller",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Status and settled usage"
          },
          "404": {
            "description": "Request does not exist or belongs to another user"
          }
        }
      }
    }
  }
}