{
  "openapi": "3.1.0",
  "info": {
    "title": "AICraft API",
    "version": "1.0.0",
    "summary": "One OpenAI-compatible endpoint for 100+ text, reasoning, image and video models.",
    "description": "AICraft exposes a single OpenAI-compatible API for 100+ models across text, reasoning, image and video generation. Point an existing OpenAI SDK at the base URL and change nothing else. Sending `\"model\": \"auto\"` activates Auto Router, which classifies each request and selects a model on quality, latency and cost with automatic failover. Naming an explicit model ID pins that model unchanged.\n\nAuthentication uses a bearer API key created in the console. Keys have the form `sk-` followed by 40 hexadecimal characters.",
    "contact": {
      "name": "AICraft Support",
      "email": "support.int@aicraftapi.net",
      "url": "https://aicraftapi.net/docs.html"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://aicraftapi.net/terms.html"
    }
  },
  "servers": [
    {
      "url": "https://aicraftapi.net",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Chat",
      "description": "Chat completion and Anthropic-compatible message endpoints."
    },
    {
      "name": "Models",
      "description": "Model discovery."
    },
    {
      "name": "Router",
      "description": "Auto Router feedback."
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "tags": [
          "Chat"
        ],
        "operationId": "createChatCompletion",
        "summary": "Create a chat completion",
        "description": "OpenAI-compatible chat completion. Send `model: \"auto\"` to let Auto Router choose, or an exact model ID in `vendor/model` lowercase form to pin a model. Responses carry routing headers: `X-AICraft-Mode` (`auto` or `manual`), `X-AICraft-Category`, `X-AICraft-Routed-To` and `X-AICraft-Savings`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A chat completion, or an SSE stream when `stream` is true.",
            "headers": {
              "X-AICraft-Mode": {
                "description": "Routing mode: `auto` when the Router chose the model, `manual` when a model ID was supplied.",
                "schema": {
                  "type": "string",
                  "enum": [
                    "auto",
                    "manual"
                  ]
                }
              },
              "X-AICraft-Category": {
                "description": "Task category detected by the Router.",
                "schema": {
                  "type": "string"
                }
              },
              "X-AICraft-Routed-To": {
                "description": "Model that actually served the request.",
                "schema": {
                  "type": "string"
                }
              },
              "X-AICraft-Savings": {
                "description": "Cost saved against GPT-4 for this request.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "One `data: {json}` chunk per delta, terminated by `data: [DONE]`."
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/ModelUnavailable"
          },
          "503": {
            "$ref": "#/components/responses/Overloaded"
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "tags": [
          "Chat"
        ],
        "operationId": "createMessage",
        "summary": "Create a message (Anthropic-compatible)",
        "description": "Anthropic Messages API compatible endpoint used by Claude Code and other Anthropic SDK clients. It runs through the same routing, rate limiting and billing path as `/v1/chat/completions`. Point `ANTHROPIC_BASE_URL` at `https://aicraftapi.net` without `/v1` — Claude Code appends `/v1/messages` itself.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MessageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An Anthropic-shaped message response, or an SSE event stream when `stream` is true.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Anthropic Messages response object."
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/ModelUnavailable"
          },
          "503": {
            "$ref": "#/components/responses/Overloaded"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "tags": [
          "Models"
        ],
        "operationId": "listModels",
        "summary": "List available models",
        "description": "Returns the models available to the calling key. The public catalogue with context windows and per-model pricing is at https://aicraftapi.net/models.html.",
        "responses": {
          "200": {
            "description": "Model list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "object": {
                            "type": "string",
                            "const": "model"
                          },
                          "created": {
                            "type": "integer"
                          },
                          "owned_by": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "object"
                        ]
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/feedback": {
      "post": {
        "tags": [
          "Router"
        ],
        "operationId": "submitRouterFeedback",
        "summary": "Submit Auto Router feedback",
        "description": "Records a preference signal that teaches Auto Router which model works for a given user. Feedback is only stored when a non-anonymous user identifier is supplied.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "user": {
                    "type": "string",
                    "description": "User identifier the preference belongs to. Ignored when absent or `anon`."
                  },
                  "rating": {
                    "type": "string",
                    "enum": [
                      "up",
                      "down"
                    ],
                    "default": "up",
                    "description": "Direction of the signal."
                  },
                  "model": {
                    "type": "string",
                    "description": "Model the rating refers to."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Feedback accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "ok"
                    },
                    "msg": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key of the form `sk-` followed by 40 hexadecimal characters."
      }
    },
    "schemas": {
      "Message": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant"
            ]
          },
          "content": {
            "type": "string"
          }
        },
        "required": [
          "role",
          "content"
        ]
      },
      "ChatCompletionRequest": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "description": "`auto` to let Auto Router choose, or an exact model ID such as `deepseek/deepseek-v4-pro`.",
            "examples": [
              "auto",
              "deepseek/deepseek-v4-pro"
            ]
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false,
            "description": "Return server-sent events instead of one JSON body."
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2,
            "default": 1
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "description": "Maximum number of tokens to generate."
          },
          "top_p": {
            "type": "number",
            "default": 1
          },
          "frequency_penalty": {
            "type": "number",
            "minimum": -2,
            "maximum": 2,
            "default": 0
          },
          "presence_penalty": {
            "type": "number",
            "minimum": -2,
            "maximum": 2,
            "default": 0
          },
          "stop": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          }
        },
        "required": [
          "model",
          "messages"
        ]
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "const": "chat.completion"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string",
            "description": "The model that served the request. With `model: \"auto\"` this is the Router-selected model."
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "message": {
                  "$ref": "#/components/schemas/Message"
                },
                "finish_reason": {
                  "type": "string"
                }
              }
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens": {
                "type": "integer"
              },
              "completion_tokens": {
                "type": "integer"
              },
              "total_tokens": {
                "type": "integer"
              }
            }
          }
        }
      },
      "MessageRequest": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "description": "`auto` to let Auto Router choose, or an exact model ID."
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "system": {
            "type": "string"
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2
          }
        },
        "required": [
          "model",
          "messages"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "code": {
                "type": "string"
              }
            },
            "required": [
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Bad request — check the JSON body and required fields.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid API key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limited — slow down or upgrade the plan.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ModelUnavailable": {
        "description": "Model unavailable — the Router retries other models.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Overloaded": {
        "description": "Service overloaded — retry shortly.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
