{
  "openapi": "3.0.1",
  "info": {
    "title": "Relace API",
    "description": "API for accessing Relace code generation models.",
    "version": "1.0.0",
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "https://models.relace.ai",
      "description": "Server for model API endpoints"
    },
    {
      "url": "https://api.relace.run",
      "description": "Server for general infrastructure"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/code/compact": {
      "post": {
        "description": "Compress an agent trace to only the important details.",
        "servers": [
          {
            "url": "https://models.relace.ai"
          }
        ],
        "requestBody": {
          "description": "Agent trace to compact",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompactRequest"
              },
              "example": {
                "messages": [
                  {
                    "role": "user",
                    "content": "Find where the rate limiter is configured and raise the ceiling to 200 rps."
                  },
                  {
                    "role": "assistant",
                    "content": "",
                    "tool_calls": [
                      {
                        "id": "call_abc123",
                        "type": "function",
                        "function": {
                          "name": "grep",
                          "arguments": "{\"pattern\": \"rate_limit\"}"
                        }
                      }
                    ]
                  },
                  {
                    "role": "tool",
                    "tool_call_id": "call_abc123",
                    "content": "config/limits.py:14: RATE_LIMIT_RPS = 100"
                  },
                  {
                    "role": "assistant",
                    "content": "Found it — the ceiling is set in config/limits.py line 14. Raising it to 200."
                  }
                ],
                "target_tokens": 96000,
                "agent_model": "gpt-5.5"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Compressed agent trace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error400"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error401"
                }
              }
            }
          },
          "402": {
            "description": "Out of credits, or no payment method on the account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error402"
                }
              }
            }
          },
          "404": {
            "description": "Route not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error404"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded, or the model is at capacity",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error429"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error500"
                }
              }
            }
          },
          "502": {
            "description": "Model server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error502"
                }
              }
            }
          },
          "503": {
            "description": "Model temporarily unavailable",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error503"
                }
              }
            }
          },
          "504": {
            "description": "Request to the model timed out",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error504"
                }
              }
            }
          }
        }
      }
    },
    "/v1/code/apply": {
      "post": {
        "description": "Merge code snippets from an LLM into your existing codebase.",
        "servers": [
          {
            "url": "https://models.relace.ai"
          }
        ],
        "requestBody": {
          "description": "Initial code and edits to apply",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstantApplyRequest"
              },
              "example": {
                "initial_code": "function calculateTotal(items) {\n  let total = 0;\n  \n  for (const item of items) {\n    total += item.price * item.quantity;\n  }\n  \n  return total;\n}",
                "edit_snippet": "// ... keep existing code\n\nfunction applyDiscount(total, discountRules) {\n  let discountedTotal = total;\n  \n  if (discountRules.percentOff) {\n    discountedTotal -= (total * discountRules.percentOff / 100);\n  }\n  \n  if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\n    discountedTotal -= discountRules.fixedAmount;\n  }\n  \n  return Math.max(0, discountedTotal);\n}",
                "stream": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Code successfully applied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstantApplyResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Stream of results from the Instant Apply model (compatible with OpenAI streaming format)"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error400"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error401"
                }
              }
            }
          },
          "402": {
            "description": "Out of credits, or no payment method on the account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error402"
                }
              }
            }
          },
          "404": {
            "description": "Route not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error404"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded, or the model is at capacity",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error429"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error500"
                }
              }
            }
          },
          "502": {
            "description": "Model server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error502"
                }
              }
            }
          },
          "503": {
            "description": "Model temporarily unavailable",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error503"
                }
              }
            }
          },
          "504": {
            "description": "Request to the model timed out",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error504"
                }
              }
            }
          }
        }
      }
    },
    "/v2/code/rank": {
      "post": {
        "description": "Assess the relevance of each file in your codebase to a user's query.",
        "servers": [
          {
            "url": "https://models.relace.ai"
          }
        ],
        "requestBody": {
          "description": "Query and codebase context for relevance scoring",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeRerankerRequest"
              },
              "example": {
                "query": "Optimize the search function for better performance with large arrays",
                "codebase": [
                  {
                    "filename": "src/search.ts",
                    "content": "function findItem(array: Item[], targetId: string): Item | undefined {\\n  for (let i = 0; i < array.length; i++) {\\n    const item = array[i];\\n    if (item.id === targetId) {\\n      return item;\\n}\\n}\\n  return undefined;\\n}"
                  }
                ],
                "token_limit": 100000
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Codebase reranked successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/v2CodeRerankerResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error400"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error401"
                }
              }
            }
          },
          "402": {
            "description": "Out of credits, or no payment method on the account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error402"
                }
              }
            }
          },
          "404": {
            "description": "Route not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error404"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded, or the model is at capacity",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error429"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error500"
                }
              }
            }
          },
          "502": {
            "description": "Model server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error502"
                }
              }
            }
          },
          "503": {
            "description": "Model temporarily unavailable",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error503"
                }
              }
            }
          },
          "504": {
            "description": "Request to the model timed out",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error504"
                }
              }
            }
          }
        }
      }
    },
    "/v1/search/chat/completions": {
      "post": {
        "description": "Run the Fast Agentic Search model (`relace-search`) one turn at a time through an OpenAI-compatible chat completions request. You supply the agent harness: the search tools and the code that executes them.",
        "servers": [
          {
            "url": "https://models.relace.ai"
          }
        ],
        "requestBody": {
          "description": "OpenAI-compatible chat completions request with the Fast Agentic Search tool definitions",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchChatCompletionsRequest"
              },
              "example": {
                "model": "relace-search",
                "messages": [
                  {
                    "role": "system",
                    "content": "You are an AI agent whose job is to explore a code base with the provided tools and thoroughly understand the problem. ..."
                  },
                  {
                    "role": "user",
                    "content": "I have uploaded a code repository in the /repo directory.\n\nNow consider the following user query:\n\n<user_query>\nHow is user authentication handled in this codebase?\n</user_query>\n\n..."
                  }
                ],
                "tools": [
                  {
                    "type": "function",
                    "function": {
                      "name": "view_file",
                      "description": "Tool for viewing/exploring the contents of existing files",
                      "parameters": {
                        "type": "object",
                        "required": ["path", "view_range"],
                        "properties": {
                          "path": {
                            "type": "string"
                          },
                          "view_range": {
                            "type": "array",
                            "items": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  },
                  {
                    "type": "function",
                    "function": {
                      "name": "report_back",
                      "description": "Report the relevant files once the codebase is understood",
                      "parameters": {
                        "type": "object",
                        "required": ["explanation", "files"],
                        "properties": {
                          "explanation": {
                            "type": "string"
                          },
                          "files": {
                            "type": "object"
                          }
                        }
                      }
                    }
                  }
                ],
                "tool_choice": "auto",
                "stream": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion generated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionsResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Stream of chat completion chunks in the OpenAI streaming format. Token usage is reported in the final chunk."
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "Out of credits, or no payment method on the account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Route not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded, or the model is at capacity",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "502": {
            "description": "Model server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Model temporarily unavailable",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "504": {
            "description": "Request to the model timed out",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          }
        }
      }
    },
    "/models": {
      "get": {
        "description": "Get the catalog for open-weight models hosted by Relace.",
        "servers": [
          {
            "url": "https://models.relace.ai"
          }
        ],
        "responses": {
          "200": {
            "description": "The hosted model catalog",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelsResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error401"
                }
              }
            }
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "description": "Send an OpenAI-compatible chat completions request to a Relace-hosted model.",
        "servers": [
          {
            "url": "https://models.relace.ai"
          }
        ],
        "requestBody": {
          "description": "OpenAI-compatible chat completions request",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionsRequest"
              },
              "example": {
                "model": "deepseek-ai/DeepSeek-V4-Flash-0731",
                "messages": [
                  {
                    "role": "user",
                    "content": "Write a binary search in Python."
                  }
                ],
                "stream": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion generated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionsResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Stream of chat completion chunks in the OpenAI streaming format. Token usage is reported in the final chunk."
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "Out of credits, or no payment method on the account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Route not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded, or the model is at capacity",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "502": {
            "description": "Model server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Model temporarily unavailable",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "504": {
            "description": "Request to the model timed out",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "description": "Send an Anthropic-compatible Messages request to a Relace-hosted model.",
        "servers": [
          {
            "url": "https://models.relace.ai"
          }
        ],
        "security": [
          {
            "apiKeyAuth": []
          },
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "description": "Anthropic-compatible Messages request",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MessagesRequest"
              },
              "example": {
                "model": "deepseek-ai/DeepSeek-V4-Flash-0731",
                "max_tokens": 1024,
                "messages": [
                  {
                    "role": "user",
                    "content": "Write a binary search in Python."
                  }
                ],
                "stream": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Message generated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessagesResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Stream of Anthropic Messages events: `message_start`, then `content_block_start` / `content_block_delta` / `content_block_stop` per content block, then `message_delta` with the stop reason and token usage, then `message_stop`."
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "402": {
            "description": "Out of credits, or no payment method on the account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "404": {
            "description": "Route not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded, or the model is at capacity",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "502": {
            "description": "Model server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "503": {
            "description": "Model temporarily unavailable",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "504": {
            "description": "Request to the model timed out",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/repo": {
      "post": {
        "description": "Create a new repository",
        "servers": [
          {
            "url": "https://api.relace.run"
          }
        ],
        "requestBody": {
          "description": "Repository creation request",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateRepoRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Repository created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateRepoResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error400"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error401"
                }
              }
            }
          }
        }
      },
      "get": {
        "description": "List all repositories",
        "servers": [
          {
            "url": "https://api.relace.run"
          }
        ],
        "parameters": [
          {
            "name": "order_by",
            "in": "query",
            "description": "Field to order results by.",
            "schema": {
              "type": "string",
              "enum": ["created_at", "updated_at"],
              "default": "created_at"
            }
          },
          {
            "name": "order_descending",
            "in": "query",
            "description": "Whether to order results in descending order.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "filter_metadata",
            "in": "query",
            "description": "URL-encoded JSON map of metadata key/value pairs to filter by.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page_start",
            "in": "query",
            "description": "Index of the first item to return (0-based)",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "description": "Number of items to return per page",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of repositories",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListReposResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error401"
                }
              }
            }
          }
        }
      }
    },
    "/v1/repo/{repo_id}": {
      "delete": {
        "description": "Delete a repository",
        "servers": [
          {
            "url": "https://api.relace.run"
          }
        ],
        "parameters": [
          {
            "name": "repo_id",
            "in": "path",
            "required": true,
            "description": "Repository ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Repository deleted successfully"
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error401"
                }
              }
            }
          },
          "404": {
            "description": "Repository not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error404"
                }
              }
            }
          }
        }
      }
    },
    "/v1/repo/{repo_id}/update": {
      "post": {
        "description": "Update repository content",
        "servers": [
          {
            "url": "https://api.relace.run"
          }
        ],
        "parameters": [
          {
            "name": "repo_id",
            "in": "path",
            "required": true,
            "description": "Repository ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "Repository update request",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateRepoRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Repository updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdateRepoResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error400"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error401"
                }
              }
            }
          },
          "404": {
            "description": "Repository not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error404"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CompactRequest": {
        "type": "object",
        "required": [
          "messages"
        ],
        "properties": {
          "messages": {
            "type": "array",
            "description": "The agent trace to compact, in OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages format. The format is detected automatically, and the compressed trace is returned in the same format.",
            "items": {
              "type": "object",
              "description": "A message in the same format as the rest of the trace"
            }
          },
          "target_tokens": {
            "type": "integer",
            "description": "Approximate token budget for the retained context, in your agent model's tokens. Defaults to 96k tokens. Counts are computed with a heuristic lookup table to reduce API latency; your provider's count may differ slightly."
          },
          "agent_model": {
            "type": "string",
            "description": "The model that generated the trace, as its API model id (e.g. `claude-fable-5`, `gpt-5.5`, `grok-4.5`). Relace uses this to apply model-specific compaction improvements and count tokens more accurately."
          }
        }
      },
      "CompactResponse": {
        "type": "object",
        "properties": {
          "messages": {
            "type": "array",
            "description": "The compressed agent trace, in the same format as the input.",
            "items": {
              "type": "object",
              "description": "A message in the same format as the input"
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens": {
                "type": "integer",
                "description": "Number of tokens in the input conversation"
              },
              "completion_tokens": {
                "type": "integer",
                "description": "Size of the retained view in the server's tokenizer"
              },
              "total_tokens": {
                "type": "integer",
                "description": "Total number of tokens used"
              }
            },
            "description": "Token usage information for the request, counted in the Relace Compact tokenizer."
          }
        },
        "example": {
          "messages": [
            {
              "role": "user",
              "content": "Find where the rate limiter is configured and raise the ceiling to 200 rps."
            },
            {
              "role": "assistant",
              "content": "Found it — the ceiling is set in config/limits.py line 14. Raising it to 200."
            }
          ],
          "usage": {
            "prompt_tokens": 135407,
            "completion_tokens": 17323,
            "total_tokens": 152730
          }
        }
      },
      "InstantApplyRequest": {
        "type": "object",
        "required": [
          "initial_code",
          "edit_snippet"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "Choice of apply model to use",
            "enum": ["relace-apply-3"],
            "default": "relace-apply-3"
          },
          "initial_code": {
            "type": "string",
            "description": "The original code that needs to be modified"
          },
          "edit_snippet": {
            "type": "string",
            "description": "The code changes to be applied to the initial code"
          },
          "instruction": {
            "type": "string",
            "description": "Optional single line instruction for to disambiguate the edit snippet. *e.g.* `Remove the captcha from the login page`"
          },
          "stream": {
            "type": "boolean",
            "description": "Whether to stream the response back",
            "default": false
          },
          "relace_metadata": {
            "type": "object",
            "description": "Optional metadata for logging and tracking purposes.",
            "additionalProperties": true
          }
        }
      },
      "InstantApplyResponse": {
        "type": "object",
        "properties": {
          "mergedCode": {
            "type": "string",
            "description": "The merged code with the changes applied"
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens": {
                "type": "integer",
                "description": "Number of tokens in the prompt"
              },
              "completion_tokens": {
                "type": "integer",
                "description": "Number of tokens in the completion"
              },
              "total_tokens": {
                "type": "integer",
                "description": "Total number of tokens used"
              }
            },
            "description": "Token usage information for the request"
          }
        },
        "example": {
          "mergedCode": "function calculateTotal(items) {\n  let total = 0;\n  \n  for (const item of items) {\n    total += item.price * item.quantity;\n  }\n  \n  return total;\n}\n\nfunction applyDiscount(total, discountRules) {\n  let discountedTotal = total;\n  \n  if (discountRules.percentOff) {\n    discountedTotal -= (total * discountRules.percentOff / 100);\n  }\n  \n  if (discountRules.fixedAmount && discountRules.fixedAmount < discountedTotal) {\n    discountedTotal -= discountRules.fixedAmount;\n  }\n  \n  return Math.max(0, discountedTotal);\n}",
          "usage": {
            "prompt_tokens": 245,
            "completion_tokens": 187,
            "total_tokens": 432
          }
        }
      },
      "CodeFile": {
        "type": "object",
        "required": [
          "filename",
          "content"
        ],
        "properties": {
          "filename": {
            "type": "string",
            "description": "The name of the file including its path"
          },
          "content": {
            "type": "string",
            "description": "The content of the file"
          }
        }
      },
      "CodeRerankerRequest": {
        "type": "object",
        "required": [
          "query",
          "codebase",
          "token_limit"
        ],
        "properties": {
          "query": {
            "type": "string",
            "description": "The natural language query describing the problem to solve"
          },
          "codebase": {
            "type": "array",
            "description": "An array of files with their content, providing context for the query",
            "items": {
              "$ref": "#/components/schemas/CodeFile"
            }
          },
          "token_limit": {
            "type": "integer",
            "description": "Maximum token limit for the response",
            "default": 100000
          },
          "relace_metadata": {
            "type": "object",
            "description": "Optional metadata for logging and tracking purposes. Removed before forwarding to origin server.",
            "additionalProperties": true
          }
        }
      },
      "v2CodeRerankerResponse": {
        "type": "object",
        "properties": {
          "results": {
            "type": "array",
            "description": "Array of files ranked by relevance to the query, with their scores",
            "items": {
              "type": "object",
              "properties": {
                "filename": {
                  "type": "string",
                  "description": "The name of the file including its path"
                },
                "score": {
                  "type": "number",
                  "description": "The relevance score for this file (between 0 and 1)",
                  "format": "float"
                }
              },
              "required": ["filename", "score"]
            },
            "example": [
              {
                "filename": "src/search.ts",
                "score": 0.953125
              }
            ]
          },
          "usage": {
            "type": "object",
            "properties": {
              "total_tokens": {
                "type": "integer",
                "description": "Total number of tokens used",
                "example": 96
              }
            },
            "description": "Token usage information for the request"
          }
        }
      },
      "FileSource": {
        "type": "object",
        "required": ["type", "files"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["files"]
          },
          "files": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["filename", "content"],
              "properties": {
                "filename": {
                  "type": "string"
                },
                "content": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "GitSource": {
        "type": "object",
        "required": ["type", "url"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["git"]
          },
          "url": {
            "type": "string"
          },
          "branch": {
            "type": "string"
          },
          "commit": {
            "type": "string"
          },
          "depth": {
            "type": "integer"
          }
        }
      },
      "CreateRepoRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "source": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/FileSource"
              },
              {
                "$ref": "#/components/schemas/GitSource"
              }
            ]
          }
        }
      },
      "CreateRepoResponse": {
        "type": "object",
        "required": ["repo_id"],
        "properties": {
          "repo_id": {
            "type": "string"
          }
        }
      },
      "ListReposResponse": {
        "type": "object",
        "required": ["items"],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["repo_id", "created_at", "metadata"],
              "properties": {
                "repo_id": {
                  "type": "string"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "updated_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "metadata": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "next_page": {
            "type": "integer",
            "description": "Index of the first item on the next page (omitted if there are no more items)"
          }
        }
      },
      "FilesOverwriteSource": {
        "type": "object",
        "required": ["type", "mode", "files"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["files"]
          },
          "mode": {
            "type": "string",
            "enum": ["overwrite"]
          },
          "files": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["filename", "content"],
              "properties": {
                "filename": {
                  "type": "string"
                },
                "content": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "FilesDiffSource": {
        "type": "object",
        "required": ["type", "mode", "operations"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["files"]
          },
          "mode": {
            "type": "string",
            "enum": ["diff"]
          },
          "operations": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "object",
                  "required": ["operation", "filename"],
                  "properties": {
                    "operation": {
                      "type": "string",
                      "enum": ["delete"]
                    },
                    "filename": {
                      "type": "string"
                    }
                  }
                },
                {
                  "type": "object",
                  "required": ["operation", "filename", "content"],
                  "properties": {
                    "operation": {
                      "type": "string",
                      "enum": ["write"]
                    },
                    "filename": {
                      "type": "string"
                    },
                    "content": {
                      "type": "string"
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "UpdateRepoRequest": {
        "type": "object",
        "required": ["source"],
        "properties": {
          "source": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/GitSource"
              },
              {
                "$ref": "#/components/schemas/FilesOverwriteSource"
              },
              {
                "$ref": "#/components/schemas/FilesDiffSource"
              }
            ]
          }
        }
      },
      "UpdateRepoResponse": {
        "type": "object",
        "required": ["commit_id"],
        "properties": {
          "commit_id": {
            "type": "string"
          }
        }
      },
      "ChatCompletionsRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "ID of the hosted model to use, e.g. `deepseek-ai/DeepSeek-V4-Flash-0731` or `moonshotai/kimi-k3`."
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "The conversation so far, as OpenAI-format message objects with `role` and `content`."
          },
          "stream": {
            "type": "boolean",
            "description": "If true, tokens are sent as server-sent events as they are generated. Token usage is always reported in the final chunk of the stream."
          },
          "max_tokens": {
            "type": "integer",
            "description": "Maximum number of tokens to generate. Reasoning tokens count toward this limit, so set a generous budget."
          },
          "temperature": {
            "type": "number",
            "description": "Sampling temperature. Higher values make output more random."
          },
          "top_p": {
            "type": "number",
            "description": "Nucleus sampling: only tokens within the top `top_p` probability mass are considered."
          },
          "top_k": {
            "type": "integer",
            "description": "Only the `top_k` most likely tokens are considered at each step."
          },
          "stop": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Up to 4 sequences at which generation stops."
          },
          "frequency_penalty": {
            "type": "number",
            "description": "Penalizes tokens by how often they have appeared so far. Range -2 to 2."
          },
          "presence_penalty": {
            "type": "number",
            "description": "Penalizes tokens that have appeared at all so far. Range -2 to 2."
          },
          "repetition_penalty": {
            "type": "number",
            "description": "Multiplicative penalty on repeated tokens. Values above 1 discourage repetition."
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "OpenAI-format function tool definitions the model may call."
          },
          "tool_choice": {
            "description": "Controls tool use: `none`, `auto`, `required`, or a specific tool."
          },
          "response_format": {
            "type": "object",
            "description": "Set to `{\"type\": \"json_object\"}` for JSON mode. Kimi K3 only."
          },
          "prompt_cache_key": {
            "type": "string",
            "maxLength": 512,
            "description": "Cache affinity key. Requests with the same key are served by the same server, improving cache hit rates for multi-turn sessions. Use a stable value per conversation or session. Compatible with OpenAI's parameter of the same name."
          }
        },
        "additionalProperties": true,
        "description": "OpenAI-compatible request. Supported sampling parameters vary slightly by model."
      },
      "ChatCompletionsResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the completion"
          },
          "object": {
            "type": "string",
            "description": "Always `chat.completion`"
          },
          "created": {
            "type": "integer",
            "description": "Unix timestamp of when the completion was created"
          },
          "model": {
            "type": "string",
            "description": "The model that served the request"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "message": {
                  "type": "object",
                  "description": "The generated message, with `role` and `content` (and `tool_calls` when the model called tools)"
                },
                "finish_reason": {
                  "type": "string",
                  "description": "Why generation stopped, e.g. `stop`, `length`, or `tool_calls`"
                }
              }
            },
            "description": "The generated completions"
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens": {
                "type": "integer",
                "description": "Number of tokens in the prompt"
              },
              "completion_tokens": {
                "type": "integer",
                "description": "Number of tokens in the completion"
              },
              "total_tokens": {
                "type": "integer",
                "description": "Total number of tokens used"
              }
            },
            "description": "Token usage information for the request"
          }
        }
      },
      "SearchChatCompletionsRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": {
            "type": "string",
            "description": "Must be `relace-search`. This route serves only the Fast Agentic Search model."
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "The agent conversation so far, as OpenAI-format message objects: the system prompt, the user prompt, and any previous `assistant` tool calls with their `tool` results."
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "OpenAI-format function tool definitions. Use the exact `view_file`, `view_directory`, `grep_search`, `bash`, and `report_back` schemas from the [agent harness guide](/docs/fast-agentic-search/agent#tool-schema-definition); the model is trained against them."
          },
          "tool_choice": {
            "description": "Controls tool use: `none`, `auto`, `required`, or a specific tool. Use `auto`."
          },
          "stream": {
            "type": "boolean",
            "description": "If true, tokens are sent as server-sent events as they are generated. Token usage is always reported in the final chunk of the stream."
          },
          "max_tokens": {
            "type": "integer",
            "description": "Maximum number of tokens to generate for this turn."
          },
          "stop": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Sequences at which generation stops."
          },
          "seed": {
            "type": "integer",
            "description": "Seed for deterministic sampling where supported."
          }
        },
        "description": "OpenAI-compatible request for one turn of the search agent. Fields outside this list are ignored."
      },
      "ModelsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Model ID to pass as `model` in chat completions requests"
                },
                "name": {
                  "type": "string",
                  "description": "Human-readable model name"
                },
                "description": {
                  "type": "string",
                  "description": "What the model is and how to use it"
                },
                "context_length": {
                  "type": "integer",
                  "description": "Maximum context length in tokens"
                },
                "max_output_length": {
                  "type": "integer",
                  "description": "Maximum output length in tokens"
                },
                "quantization": {
                  "type": "string",
                  "description": "Quantization the model is served at, e.g. `fp4`, `fp8`, `bf16`"
                },
                "input_modalities": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "description": "Accepted input modalities, e.g. `text`, `image`"
                },
                "output_modalities": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "description": "Produced output modalities"
                },
                "pricing": {
                  "type": "object",
                  "properties": {
                    "prompt": {
                      "type": "string",
                      "description": "Price per prompt token, in dollars"
                    },
                    "completion": {
                      "type": "string",
                      "description": "Price per completion token, in dollars"
                    },
                    "input_cache_reads": {
                      "type": "string",
                      "description": "Price per prompt token served from the prefix cache, in dollars"
                    }
                  },
                  "description": "Per-token prices, as decimal strings in dollars"
                },
                "supported_sampling_parameters": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "description": "Sampling parameters the model accepts"
                },
                "supported_features": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "description": "Supported features, e.g. `tools`, `json_mode`, `structured_outputs`, `reasoning`"
                }
              }
            },
            "description": "The available hosted models"
          }
        }
      },
      "Error400": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Invalid JSON in the request body."
          }
        }
      },
      "Error401": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Invalid API key. Check the key, or create one at https://app.relace.ai."
          }
        }
      },
      "Error404": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Route not found: POST /v1/code/rank"
          }
        }
      },
      "Error429": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Rate limit exceeded. Retry after the Retry-After interval, or contact support to raise your limits."
          }
        }
      },
      "Error500": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Internal server error."
          }
        }
      },
      "Error402": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Out of credits. Add credits at https://app.relace.ai to continue."
          }
        }
      },
      "Error502": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Model server error; retry shortly."
          }
        }
      },
      "Error503": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Model 'relace-apply-3' is temporarily unavailable; retry shortly."
          }
        }
      },
      "Error504": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Request to the model timed out after 60s."
          }
        }
      },
      "OpenAIError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string",
                "description": "Error message",
                "example": "Rate limit exceeded. Retry after the Retry-After interval, or contact support to raise your limits."
              },
              "type": {
                "type": "string",
                "description": "OpenAI error type",
                "enum": ["invalid_request_error", "authentication_error", "insufficient_quota", "rate_limit_error", "api_error"],
                "example": "rate_limit_error"
              },
              "param": {
                "type": "string",
                "nullable": true,
                "description": "Offending request parameter, when known",
                "example": null
              },
              "code": {
                "type": "string",
                "nullable": true,
                "description": "Always null on Relace-authored errors",
                "example": null
              }
            }
          }
        }
      },
      "MessagesRequest": {
        "type": "object",
        "required": [
          "model",
          "max_tokens",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "ID of the hosted model to use, e.g. `deepseek-ai/DeepSeek-V4-Flash-0731` or `moonshotai/kimi-k3`."
          },
          "max_tokens": {
            "type": "integer",
            "description": "Maximum number of tokens to generate. Reasoning tokens count toward this limit, so set a generous budget."
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "The conversation so far, as Anthropic-format message objects with `role` (`user` or `assistant`) and `content` (a string, or an array of `text`, `image`, `tool_use`, `tool_result`, and `thinking` blocks)."
          },
          "system": {
            "description": "System prompt, as a string or an array of `text` blocks."
          },
          "stream": {
            "type": "boolean",
            "description": "If true, the response is sent as server-sent events in the Anthropic streaming format. Token usage is reported in the `message_delta` event."
          },
          "temperature": {
            "type": "number",
            "description": "Sampling temperature. Higher values make output more random."
          },
          "top_p": {
            "type": "number",
            "description": "Nucleus sampling: only tokens within the top `top_p` probability mass are considered."
          },
          "top_k": {
            "type": "integer",
            "description": "Only the `top_k` most likely tokens are considered at each step."
          },
          "stop_sequences": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Up to 4 sequences at which generation stops."
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Anthropic-format tool definitions with `name`, `description`, and `input_schema`. Server tools are ignored."
          },
          "tool_choice": {
            "type": "object",
            "description": "Controls tool use: `{\"type\": \"auto\"}`, `{\"type\": \"any\"}`, `{\"type\": \"tool\", \"name\": ...}`, or `{\"type\": \"none\"}`. `any` and a named tool require a model with forced tool choice; others are served as `auto`. Set `disable_parallel_tool_use` to limit the model to one call per turn."
          },
          "thinking": {
            "type": "object",
            "description": "`{\"type\": \"enabled\"}` or `{\"type\": \"adaptive\"}` turns reasoning on; `{\"type\": \"disabled\"}` turns it off. `budget_tokens` is accepted but not enforced."
          },
          "output_config": {
            "type": "object",
            "description": "`effort` (`low` to `max`) maps onto the model's reasoning effort levels where it has them. `format` is accepted and ignored."
          },
          "metadata": {
            "type": "object",
            "properties": {
              "user_id": {
                "type": "string",
                "maxLength": 512,
                "description": "Cache affinity key. Requests with the same value are served by the same server, improving cache hit rates for multi-turn sessions. Use a stable value per conversation or session."
              }
            }
          }
        },
        "additionalProperties": true,
        "description": "Anthropic-compatible request. `cache_control` markers and other Anthropic-only fields are accepted and ignored. Supported sampling parameters vary slightly by model."
      },
      "MessagesResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the message, prefixed `msg_`"
          },
          "type": {
            "type": "string",
            "description": "Always `message`"
          },
          "role": {
            "type": "string",
            "description": "Always `assistant`"
          },
          "model": {
            "type": "string",
            "description": "The model that served the request"
          },
          "content": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "The generated content blocks, in order: `thinking` (when reasoning is on), `text`, and `tool_use` (with the call's `id`, `name`, and parsed `input`)"
          },
          "stop_reason": {
            "type": "string",
            "description": "Why generation stopped: `end_turn`, `max_tokens`, `stop_sequence`, or `tool_use`"
          },
          "stop_sequence": {
            "type": "string",
            "nullable": true,
            "description": "The matched stop sequence when `stop_reason` is `stop_sequence`; otherwise null"
          },
          "usage": {
            "type": "object",
            "properties": {
              "input_tokens": {
                "type": "integer",
                "description": "Prompt tokens not served from cache"
              },
              "cache_read_input_tokens": {
                "type": "integer",
                "description": "Prompt tokens served from cache, billed at the Cached Input rate"
              },
              "cache_creation_input_tokens": {
                "type": "integer",
                "description": "Always 0; writing to the cache is free"
              },
              "output_tokens": {
                "type": "integer",
                "description": "Tokens generated, including reasoning"
              }
            },
            "description": "Token usage information for the request"
          }
        }
      },
      "AnthropicError": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "Always `error`",
            "example": "error"
          },
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "description": "Anthropic error type",
                "enum": [
                  "invalid_request_error",
                  "authentication_error",
                  "billing_error",
                  "permission_error",
                  "not_found_error",
                  "request_too_large",
                  "rate_limit_error",
                  "api_error",
                  "overloaded_error",
                  "timeout_error"
                ],
                "example": "rate_limit_error"
              },
              "message": {
                "type": "string",
                "description": "Error message",
                "example": "Rate limit exceeded. Retry after the Retry-After interval, or contact support to raise your limits."
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Relace API key Authorization header using the Bearer scheme."
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Relace API key in the `x-api-key` header, as the Anthropic SDKs send it. Accepted on `/v1/messages` only."
      }
    },
    "parameters": {
      "X-Relace-Headers": {
        "name": "X-Relace-*",
        "in": "header",
        "description": "Custom headers starting with X-Relace- prefix are captured for logging purposes",
        "schema": {
          "type": "string"
        },
        "required": false
      }
    }
  }
}