> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.0x.org/llms.txt.
> For full documentation content, see https://docs.0x.org/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.0x.org/_mcp/server.

# Swap Instructions

POST https://host.com/swap-instructions
Content-Type: application/json

Get swap instructions

Reference: https://docs.0x.org/api-reference/solana-swap-ap-is/solana-swap/solana-swap-swap-instructions

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: solana
  version: 1.0.0
paths:
  /swap-instructions:
    post:
      operationId: solana-swap-swap-instructions
      summary: Swap Instructions
      description: Get swap instructions
      tags:
        - subpackage_solanaSwap
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/Solana
                  Swap_solanaSwap_swapInstructions_Response_200
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapInstructions.SwapInstructionRequest'
servers:
  - url: https://host.com
components:
  schemas:
    SwapInstructions.SwapInstructionRequest:
      type: object
      properties:
        token_out:
          type: string
          description: >-
            Output Token Mint. For native SOL output, use
            `So11111111111111111111111111111111111111111`.
        token_in:
          type: string
          description: >-
            Input Token Mint. For native SOL input, use
            `So11111111111111111111111111111111111111111`.
        amount_in:
          type: integer
          format: uint64
          description: Amount of `tokenIn` in its base units
        taker:
          type: string
          description: Taker Account.
        slippage_bps:
          type: integer
          description: >-
            Optional. Slippage tolerance in basis points (bps). Must be between
            0 and 10,000. Default is 50 bps (0.5%).
        recipient:
          type: string
          description: >-
            Optional. Recipient for swap output. If output token is native SOL
            this must be the address of the recipient, else a valid token
            account for that output token mint
        reserve_transaction_bytes:
          type: integer
          description: >-
            Optional. Requests a minimum number of bytes be free in the returned
            transaction, for composing the swap with additional instructions.
            Default is 0 bytes.
        swap_fee_ppm:
          type: string
          description: >-
            Optional. Comma-separated volume-based swap fees in parts per
            million (ppm). Must be provided together with `swap_fee_recipient`.
            Each entry must be between `0` and `1_000_000`. A value of `0`
            disables that fee entry. Fees are applied sequentially on the same
            side: each entry is charged on the remaining amount after previous
            entries on that side have been deducted, and each fee amount is
            rounded up to the next base unit when needed (e.g. with
            `swap_fee_ppm=50000,25000` both on the buy side, the second fee is
            25000ppm of the amount remaining after the first fee, not of the
            original amount).
        swap_fee_recipient:
          type: string
          description: >-
            Optional. Comma-separated recipients for the swap fees. Must be
            provided together with `swap_fee_ppm`. The number of entries must
            match `swap_fee_ppm`. If the respective token for `swap_fee_side` is
            native SOL this must be an address, else a valid token account for
            that token mint.
        swap_fee_side:
          type: string
          description: >-
            Optional. Comma-separated fee sides for each fee entry. Supported
            values are `buy` and `sell`. This field may be omitted only when
            every fee uses the default `buy` side. When provided, the number of
            entries must match `swap_fee_ppm`.
        trade_surplus_cap_ppm:
          type: integer
          format: uint
          description: >-
            Optional. Trade surplus cap in parts per million of the total
            realized trade size. Must be provided together with
            `trade_surplus_token_account`, or both fields must be omitted. A
            value of `0` disables trade surplus collection for the request. When
            0x controls trade surplus collection, the request value is ignored
            and the configured 0x policy is applied instead. The transferred
            amount is capped relative to trade size.
        trade_surplus_recipient:
          type: string
          description: >-
            Optional. Recipient that should receive trade surplus. Must be
            provided together with `trade_surplus_cap_ppm`, or both fields must
            be omitted. If the output token is native SOL this must be an
            address, else a valid token account for that token mint. When 0x
            controls trade surplus collection, the request value is ignored and
            the configured 0x recipient is used instead.
      required:
        - token_out
        - token_in
        - amount_in
        - taker
      description: Request payload for the swap-instruction endpoint.
      title: SwapInstructions.SwapInstructionRequest
    SolanaTypes.AccountMeta:
      type: object
      properties:
        pubkey:
          type: array
          items:
            type: integer
          description: Public key of the account
        is_signer:
          type: boolean
          description: True if the account is a signer
        is_writable:
          type: boolean
          description: True if the account is writable
      required:
        - pubkey
        - is_signer
        - is_writable
      description: Account metadata.
      title: SolanaTypes.AccountMeta
    SolanaTypes.Instruction:
      type: object
      properties:
        program_id:
          type: array
          items:
            type: integer
          description: Program ID executing the instruction.
        accounts:
          type: array
          items:
            $ref: '#/components/schemas/SolanaTypes.AccountMeta'
          description: List of accounts used by the instruction.
        data:
          type: array
          items:
            type: integer
          description: Instruction Data.
      required:
        - program_id
        - accounts
        - data
      description: Solana instruction.
      title: SolanaTypes.Instruction
    SwapInstructions.SwapInstructionResponse:
      type: object
      properties:
        amount_out:
          type: integer
          format: uint64
          description: The estimated amount of the output token received from the swap.
        instructions:
          type: array
          items:
            $ref: '#/components/schemas/SolanaTypes.Instruction'
          description: Swap Instructions.
        address_lookup_tables:
          type: array
          items:
            type: string
          description: >-
            Lookup table addresses that must be included as part of serialized
            versioned transaction.
        zid:
          type: string
          description: The unique ZeroEx 12 byte hex identifier of the request.
      required:
        - amount_out
        - instructions
        - address_lookup_tables
        - zid
      description: Response model for the swap-instruction endpoint.
      title: SwapInstructions.SwapInstructionResponse
    SolanaTypes.Error:
      type: object
      properties:
        code:
          type: string
          description: Error code
        message:
          type: string
          description: Error message
      required:
        - code
        - message
      description: Error response model.
      title: SolanaTypes.Error
    Solana Swap_solanaSwap_swapInstructions_Response_200:
      oneOf:
        - $ref: '#/components/schemas/SwapInstructions.SwapInstructionResponse'
        - $ref: '#/components/schemas/SolanaTypes.Error'
      title: Solana Swap_solanaSwap_swapInstructions_Response_200

```

## SDK Code Examples

```python
import requests

url = "https://host.com/swap-instructions"

payload = {
    "token_out": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "token_in": "So11111111111111111111111111111111111111112",
    "amount_in": 100000000000,
    "taker": "3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://host.com/swap-instructions';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"token_out":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","token_in":"So11111111111111111111111111111111111111112","amount_in":100000000000,"taker":"3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://host.com/swap-instructions"

	payload := strings.NewReader("{\n  \"token_out\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n  \"token_in\": \"So11111111111111111111111111111111111111112\",\n  \"amount_in\": 100000000000,\n  \"taker\": \"3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://host.com/swap-instructions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"token_out\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n  \"token_in\": \"So11111111111111111111111111111111111111112\",\n  \"amount_in\": 100000000000,\n  \"taker\": \"3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://host.com/swap-instructions")
  .header("Content-Type", "application/json")
  .body("{\n  \"token_out\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n  \"token_in\": \"So11111111111111111111111111111111111111112\",\n  \"amount_in\": 100000000000,\n  \"taker\": \"3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://host.com/swap-instructions', [
  'body' => '{
  "token_out": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "token_in": "So11111111111111111111111111111111111111112",
  "amount_in": 100000000000,
  "taker": "3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://host.com/swap-instructions");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"token_out\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n  \"token_in\": \"So11111111111111111111111111111111111111112\",\n  \"amount_in\": 100000000000,\n  \"taker\": \"3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "token_out": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "token_in": "So11111111111111111111111111111111111111112",
  "amount_in": 100000000000,
  "taker": "3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://host.com/swap-instructions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```