> 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 AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.0x.org/_mcp/server.

# Create Swap Instructions

POST https://api.0x.org/solana/swap-instructions
Content-Type: application/json

Returns Solana swap instructions for a given token pair and amount.

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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: solana
  version: 1.0.0
paths:
  /swap-instructions:
    post:
      operationId: instructions
      summary: Create Swap Instructions
      description: Returns Solana swap instructions for a given token pair and amount.
      tags:
        - swap
      parameters:
        - name: 0x-api-key
          in: header
          description: Visit dashboard.0x.org to get your API Key
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Swap instructions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwapInstructionsResponse'
        '400':
          description: Client error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapInstructionsRequest'
servers:
  - url: https://api.0x.org/solana
    description: https://api.0x.org/solana
components:
  schemas:
    SwapInstructionsRequest:
      type: object
      properties:
        amount_in:
          type: integer
          format: int64
          description: Input amount in its base units.
        disabled_sources:
          type: array
          items:
            type: string
          description: >-
            DEX sources to exclude from routing. Valid source names are returned
            by `/enabled-sources`.
        recipient:
          type: string
          description: >-
            Base-58 encoded 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
          format: int64
          default: 0
          description: >-
            Minimum bytes to reserve in the transaction for composing with
            additional instructions.
        slippage_bps:
          type: integer
          default: 50
          description: Slippage tolerance in basis points.
        swap_fee_ppm:
          type: string
          description: >-
            Comma-separated volume-based swap fees in parts per million.

            Must be provided together with `swap_fee_recipient`.

            Each entry must be between `0` and the per-app maximum (`100_000`
            unless configured otherwise).

            A value of `0` disables that fee entry.

            Multiple fees on the same side are applied sequentially, each on the
            amount remaining after prior deductions — not the original amount.
            Fee amounts are rounded up to the nearest base unit.
        swap_fee_recipient:
          type: string
          description: >-
            Comma-separated base-58 encoded 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: >-
            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`.
        taker:
          type: string
          description: Base-58 encoded taker wallet address.
        token_in:
          type: string
          description: >-
            Input token mint, base-58 encoded. Use
            `So11111111111111111111111111111111111111111` for native SOL.
        token_out:
          type: string
          description: >-
            Output token mint, base-58 encoded. Use
            `So11111111111111111111111111111111111111111` for native SOL.
        trade_surplus_cap_ppm:
          type: integer
          description: >-
            Trade surplus cap in parts per million of the total realized trade
            size.

            Must be provided together with `trade_surplus_recipient`, 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: >-
            Base-58 encoded 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:
        - amount_in
        - taker
        - token_in
        - token_out
      description: Request body for the swap-instructions endpoint.
      title: SwapInstructionsRequest
    AccountMeta:
      type: object
      properties:
        is_signer:
          type: boolean
        is_writable:
          type: boolean
        pubkey:
          type: array
          items:
            type: integer
          description: Account public key as a 32-byte array.
      required:
        - is_signer
        - is_writable
        - pubkey
      description: OpenAPI schema mirror for `solana_instruction::AccountMeta`.
      title: AccountMeta
    Instruction:
      type: object
      properties:
        accounts:
          type: array
          items:
            $ref: '#/components/schemas/AccountMeta'
        data:
          type: array
          items:
            type: integer
          description: Serialized instruction data bytes.
        program_id:
          type: array
          items:
            type: integer
          description: Program ID as a 32-byte array.
      required:
        - accounts
        - data
        - program_id
      description: OpenAPI schema mirror for `solana_instruction::Instruction`.
      title: Instruction
    SwapInstructionsRoutePlanStep:
      type: object
      properties:
        amount_in:
          type: string
          description: The amount of the input token to swap, in its base units.
        amount_out:
          type: string
          description: >-
            The estimated amount of the output token received from the swap, in
            its base units.
        dex_address:
          type: string
          description: The Base58-encoded address of the DEX.
        dex_label:
          type: string
          description: >-
            The label for the DEX. Matches labels returned by the
            `enabled-sources` endpoint.
        dex_program_id:
          type: string
          description: The Base58-encoded program ID address of the DEX.
        ppb:
          type: integer
          description: >-
            Proportion of _remaining_ amount routed through this step in parts
            per billion.
        token_in:
          type: string
          description: The Base58-encoded address of the input mint.
        token_out:
          type: string
          description: The Base58-encoded address of the output mint.
      required:
        - amount_in
        - amount_out
        - dex_address
        - dex_label
        - dex_program_id
        - ppb
        - token_in
        - token_out
      title: SwapInstructionsRoutePlanStep
    SwapInstructionsResponse:
      type: object
      properties:
        address_lookup_tables:
          type: array
          items:
            type: string
          description: >-
            Address Lookup Table addresses that must be included in the
            versioned transaction.
        amount_out:
          type: integer
          format: int64
          description: >-
            The estimated amount of the output token received from the swap, in
            its base units.
        instructions:
          type: array
          items:
            $ref: '#/components/schemas/Instruction'
          description: The instructions to perform the swap.
        route_plan:
          type: array
          items:
            $ref: '#/components/schemas/SwapInstructionsRoutePlanStep'
          description: List of swap legs comprising the swap.
        zid:
          type: string
          description: Unique 12-byte hex identifier for this request.
      required:
        - address_lookup_tables
        - amount_out
        - instructions
        - zid
      description: Swap instructions API response.
      title: SwapInstructionsResponse
    ApiError:
      type: object
      properties:
        code:
          type: string
        error:
          type: string
        zid:
          type: string
      required:
        - code
        - error
      description: API error response body.
      title: ApiError

```

## Examples



**Request**

```json
{
  "amount_in": 1000000000,
  "taker": "ZeroEx1111111111111111111111111111111111111",
  "token_in": "So11111111111111111111111111111111111111112",
  "token_out": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "slippage_bps": 50
}
```

**Response**

```json
{
  "address_lookup_tables": [
    "string"
  ],
  "amount_out": 1,
  "instructions": [
    {
      "accounts": [
        {
          "is_signer": true,
          "is_writable": true,
          "pubkey": [
            1
          ]
        }
      ],
      "data": [
        1
      ],
      "program_id": [
        1
      ]
    }
  ],
  "zid": "string",
  "route_plan": [
    {
      "amount_in": "string",
      "amount_out": "string",
      "dex_address": "string",
      "dex_label": "string",
      "dex_program_id": "string",
      "ppb": 1,
      "token_in": "string",
      "token_out": "string"
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "https://api.0x.org/solana/swap-instructions"

payload = {
    "amount_in": 1000000000,
    "taker": "ZeroEx1111111111111111111111111111111111111",
    "token_in": "So11111111111111111111111111111111111111112",
    "token_out": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "slippage_bps": 50
}
headers = {
    "0x-api-key": "0x-api-key",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.0x.org/solana/swap-instructions';
const options = {
  method: 'POST',
  headers: {'0x-api-key': '0x-api-key', 'Content-Type': 'application/json'},
  body: '{"amount_in":1000000000,"taker":"ZeroEx1111111111111111111111111111111111111","token_in":"So11111111111111111111111111111111111111112","token_out":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","slippage_bps":50}'
};

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://api.0x.org/solana/swap-instructions"

	payload := strings.NewReader("{\n  \"amount_in\": 1000000000,\n  \"taker\": \"ZeroEx1111111111111111111111111111111111111\",\n  \"token_in\": \"So11111111111111111111111111111111111111112\",\n  \"token_out\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n  \"slippage_bps\": 50\n}")

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

	req.Header.Add("0x-api-key", "0x-api-key")
	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://api.0x.org/solana/swap-instructions")

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

request = Net::HTTP::Post.new(url)
request["0x-api-key"] = '0x-api-key'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"amount_in\": 1000000000,\n  \"taker\": \"ZeroEx1111111111111111111111111111111111111\",\n  \"token_in\": \"So11111111111111111111111111111111111111112\",\n  \"token_out\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n  \"slippage_bps\": 50\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://api.0x.org/solana/swap-instructions")
  .header("0x-api-key", "0x-api-key")
  .header("Content-Type", "application/json")
  .body("{\n  \"amount_in\": 1000000000,\n  \"taker\": \"ZeroEx1111111111111111111111111111111111111\",\n  \"token_in\": \"So11111111111111111111111111111111111111112\",\n  \"token_out\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n  \"slippage_bps\": 50\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.0x.org/solana/swap-instructions', [
  'body' => '{
  "amount_in": 1000000000,
  "taker": "ZeroEx1111111111111111111111111111111111111",
  "token_in": "So11111111111111111111111111111111111111112",
  "token_out": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "slippage_bps": 50
}',
  'headers' => [
    '0x-api-key' => '0x-api-key',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.0x.org/solana/swap-instructions");
var request = new RestRequest(Method.POST);
request.AddHeader("0x-api-key", "0x-api-key");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"amount_in\": 1000000000,\n  \"taker\": \"ZeroEx1111111111111111111111111111111111111\",\n  \"token_in\": \"So11111111111111111111111111111111111111112\",\n  \"token_out\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n  \"slippage_bps\": 50\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "0x-api-key": "0x-api-key",
  "Content-Type": "application/json"
]
let parameters = [
  "amount_in": 1000000000,
  "taker": "ZeroEx1111111111111111111111111111111111111",
  "token_in": "So11111111111111111111111111111111111111112",
  "token_out": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "slippage_bps": 50
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.0x.org/solana/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()
```