{
  "openapi": "3.1.0",
  "info": {
    "title": "BulkToken API",
    "version": "2026-09-28",
    "description": "Chat Completions and model discovery for the currently published BulkToken text models. Optional parameters and media formats remain model-dependent."
  },
  "servers": [
    {
      "url": "https://bulktoken.ai/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Create a chat completion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion, or an SSE stream when stream is true.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "SSE data frames containing chat.completion.chunk objects, ending with data: [DONE] on normal completion."
                }
              }
            }
          },
          "400": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          },
          "401": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          },
          "403": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          },
          "429": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          },
          "500": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          },
          "502": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          },
          "503": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          },
          "504": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          }
        }
      }
    },
    "/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List models visible to the current API key",
        "responses": {
          "200": {
            "description": "Key-scoped model discovery. Does not return model pricing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string"
                    },
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Model"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          },
          "403": {
            "description": "Inspect HTTP status and the error message. Upstream responses and proxy failures can differ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/APIError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "ChatCompletionRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": {
            "type": "string",
            "description": "Exact BulkToken model ID, visible to the API key.",
            "example": "glm-5.3"
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "description": "Conversation messages in order. Include relevant prior turns and tool results.",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false,
            "description": "Use true for Server-Sent Events, false for a single JSON response."
          },
          "stream_options": {
            "type": "object",
            "description": "Streaming options; route support varies.",
            "properties": {
              "include_usage": {
                "type": "boolean",
                "description": "Request a usage chunk where supported. Its choices array can be empty."
              }
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "description": "Optional completion-token budget. Accepted limits and reasoning-token accounting depend on the model and route. Do not assume the published maximum is the default."
          },
          "temperature": {
            "type": "number",
            "description": "Optional sampling control. Accepted range, default, and compatibility with reasoning mode depend on the model."
          },
          "top_p": {
            "type": "number",
            "description": "Optional nucleus sampling control. Support and interaction with temperature depend on the model."
          },
          "stop": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ],
            "description": "Optional stop sequence or sequences, where supported."
          },
          "response_format": {
            "type": "object",
            "description": "Model-dependent output formatting, such as {\"type\":\"json_object\"}. Strict json_schema support must be checked per model and route.",
            "properties": {
              "type": {
                "type": "string"
              }
            },
            "additionalProperties": true
          },
          "tools": {
            "type": "array",
            "description": "Function definitions for tool calling. Your application validates and executes requested tools.",
            "items": {
              "type": "object",
              "required": ["type", "function"],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": ["function"]
                },
                "function": {
                  "type": "object",
                  "required": ["name", "parameters"],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    },
                    "parameters": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  }
                }
              }
            }
          }
        }
      },
      "Message": {
        "type": "object",
        "required": ["role"],
        "properties": {
          "role": {
            "type": "string",
            "enum": ["system", "developer", "user", "assistant", "tool"],
            "description": "Roles accepted depend on the selected model."
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              },
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            ],
            "description": "Text or model-supported content parts. Can be null for an assistant tool-call message."
          },
          "tool_calls": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["id", "type", "function"],
              "properties": {
                "id": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                },
                "function": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "arguments": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "tool_call_id": {
            "type": "string",
            "description": "For tool results, the ID from the matching assistant tool call."
          },
          "reasoning_content": {
            "type": ["string", "null"],
            "description": "Model-specific reasoning. Preserve when required for a tool round trip."
          }
        },
        "additionalProperties": true
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "message": {
                  "$ref": "#/components/schemas/Message"
                },
                "finish_reason": {
                  "type": ["string", "null"]
                }
              }
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        },
        "additionalProperties": true
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": {
            "type": "integer"
          },
          "completion_tokens": {
            "type": "integer"
          },
          "total_tokens": {
            "type": "integer"
          }
        },
        "additionalProperties": true
      },
      "Model": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string"
          },
          "created": {
            "type": "integer"
          },
          "owned_by": {
            "type": "string"
          },
          "supported_endpoint_types": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "APIError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "code": {
                "type": ["string", "null"]
              },
              "param": {
                "type": ["string", "null"]
              }
            },
            "additionalProperties": true
          }
        }
      }
    }
  }
}
