---
agentTools:
  projectIndex: https://ociswap.readme.io/llms.txt
---

# Returns a preview for a swap including routing. Only one of the two optional parameters (input_amount, output_amount) should be specified, and the other will be calculated and returned based on this value.

Preview for a swap including routing

# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "version": "0.6.1",
    "title": "Ociswap API",
    "description": "Ociswap API",
    "license": {
      "name": "MIT License",
      "url": "https://api.ociswap.com/license"
    }
  },
  "servers": [
    {
      "url": "https://api.ociswap.com"
    }
  ],
  "security": [],
  "paths": {
    "/preview/swap": {
      "get": {
        "operationId": "swap_preview",
        "description": "Preview for a swap including routing",
        "summary": "Returns a preview for a swap including routing. Only one of the two optional parameters (input_amount, output_amount) should be specified, and the other will be calculated and returned based on this value.",
        "parameters": [
          {
            "name": "input_address",
            "in": "query",
            "description": "The token address of the input token.",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/ResourceAddress"
            }
          },
          {
            "name": "input_amount",
            "in": "query",
            "description": "The amount of the input token. If left empty, this will be the calculated value.",
            "schema": {
              "$ref": "#/components/schemas/Decimal"
            }
          },
          {
            "name": "output_address",
            "in": "query",
            "description": "The token address of the output token.",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/ResourceAddress"
            }
          },
          {
            "name": "output_amount",
            "in": "query",
            "description": "The amount of the output token. If left empty, this will be the calculated value.",
            "schema": {
              "$ref": "#/components/schemas/Decimal"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreviewSwap"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "description": "Not found",
            "$ref": "#/components/responses/Error"
          },
          "500": {
            "description": "An unexpected error occured",
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "Error": {
        "description": "Error response",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "error"
              ],
              "properties": {
                "error": {
                  "type": "string",
                  "description": "Error message"
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "ComponentAddress": {
        "description": "Bech32m-encoded human readable version of the component (normal, account, system) global address or hex-encoded id.",
        "type": "string"
      },
      "ResourceAddress": {
        "description": "Bech32m-encoded human readable version of the resource (fungible, non-fungible) global address or hex-encoded id.",
        "type": "string"
      },
      "Decimal": {
        "description": "String-encoded decimal representing the amount of a related fungible resource.",
        "type": "string",
        "format": "decimal"
      },
      "Amounts": {
        "type": "object",
        "properties": {
          "token": {
            "$ref": "#/components/schemas/Decimal"
          },
          "xrd": {
            "$ref": "#/components/schemas/Decimal"
          },
          "usd": {
            "$ref": "#/components/schemas/Decimal"
          }
        }
      },
      "PreviewSwap": {
        "type": "object",
        "properties": {
          "input_address": {
            "$ref": "#/components/schemas/ResourceAddress"
          },
          "input_amount": {
            "$ref": "#/components/schemas/Amounts"
          },
          "output_address": {
            "$ref": "#/components/schemas/ResourceAddress"
          },
          "output_amount": {
            "$ref": "#/components/schemas/Amounts"
          },
          "input_fee_lp": {
            "$ref": "#/components/schemas/Amounts"
          },
          "price_impact": {
            "$ref": "#/components/schemas/Decimal"
          },
          "swaps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Swap"
            }
          }
        }
      },
      "Swap": {
        "type": "object",
        "properties": {
          "pool_address": {
            "$ref": "#/components/schemas/ComponentAddress"
          },
          "input_address": {
            "$ref": "#/components/schemas/ResourceAddress"
          },
          "input_amount": {
            "$ref": "#/components/schemas/Amounts"
          },
          "input_take": {
            "description": "Take all or only the specified amount from the worktop as swap input",
            "type": "string",
            "enum": [
              "all",
              "amount"
            ]
          },
          "output_address": {
            "$ref": "#/components/schemas/ResourceAddress"
          },
          "output_amount": {
            "$ref": "#/components/schemas/Amounts"
          },
          "input_fee_lp": {
            "$ref": "#/components/schemas/Amounts"
          },
          "price_impact": {
            "$ref": "#/components/schemas/Decimal"
          }
        }
      }
    }
  },
  "x-readme": {
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "_id": {
    "buffer": {
      "0": 101,
      "1": 18,
      "2": 175,
      "3": 145,
      "4": 46,
      "5": 146,
      "6": 246,
      "7": 0,
      "8": 30,
      "9": 1,
      "10": 34,
      "11": 138
    }
  }
}
```