> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xquik.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Buy X API credits for tweets, followers & writes

> Create a hosted checkout for at least USD 10 of tweet, profile, follower, monitor, webhook, export, and X write API credits. Returns one redirect URL.

<Panel>
  <Tabs defaultTabIndex={0} sync={false}>
    <Tab title="200" id="response-credits-topup-200">
      ```json theme={null}
      {
        "redirect_url": "https://xquik.com/api/v1/credits/topup/redirect?session_id=checkout_example",
        "url": "https://xquik.com/api/v1/credits/topup/redirect?session_id=checkout_example"
      }
      ```
    </Tab>

    <Tab title="400" id="response-credits-topup-400">
      ```json theme={null}
      {
        "error": "invalid_input",
        "message": "Invalid input. Check the request body."
      }
      ```
    </Tab>

    <Tab title="401" id="response-credits-topup-401">
      ```json theme={null}
      {
        "error": "unauthenticated",
        "message": "Authentication required. Provide a valid API key or bearer token."
      }
      ```
    </Tab>

    <Tab title="429" id="response-credits-topup-429">
      ```json theme={null}
      {
        "error": "rate_limit_exceeded",
        "message": "Too many requests. Try again later.",
        "retryAfter": 60
      }
      ```
    </Tab>
  </Tabs>
</Panel>

<blockquote className="agent-llms-directive">
  For the complete documentation index, see <a href="/llms.txt">llms.txt</a>.
</blockquote>

## When to use hosted checkout

Use this route when the buyer needs a hosted checkout. Use quick top-up for a saved payment method. Use top-up status only to poll an existing checkout session. Store the `session_id` from the returned URL before redirecting the user. The status route needs it.

<Callout icon="circle-check" color="#16a34a">
  **Free.** This endpoint does not consume credits.
</Callout>

Ask the user to confirm the dollar amount before calling this endpoint. The response returns a hosted checkout URL. The call does not complete payment or add credits.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://xquik.com/api/v1/credits/topup \
    -H "x-api-key: xq_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{"dollars": 10}' | jq
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://xquik.com/api/v1/credits/topup", {
    method: "POST",
    headers: {
      "x-api-key": "xq_your_api_key_here",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ dollars: 10 }),
  });
  const data = await response.json();
  process.stdout.write(`${JSON.stringify(data, null, 2)}\n`);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://xquik.com/api/v1/credits/topup",
      headers={"x-api-key": "xq_your_api_key_here"},
      json={"dollars": 10},
  )
  data = response.json()
  print(data)
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "net/http"
  )

  func main() {
      body, _ := json.Marshal(map[string]interface{}{
          "dollars": 10,
      })

      req, err := http.NewRequest("POST", "https://xquik.com/api/v1/credits/topup", bytes.NewReader(body))
      if err != nil {
          panic(err)
      }
      req.Header.Set("x-api-key", "xq_your_api_key_here")
      req.Header.Set("Content-Type", "application/json")

      resp, err := http.DefaultClient.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      var data map[string]interface{}
      if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
          panic(err)
      }
      fmt.Println(data)
  }
  ```
</CodeGroup>

## Headers

<ParamField header="x-api-key" type="string" required>
  Your API key. Session cookie authentication is also supported.
</ParamField>

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`.
</ParamField>

## Body

<ParamField body="dollars" type="number" required>
  Amount in US dollars to top up. Minimum \$10.
</ParamField>

<ParamField body="locale" type="string">
  Optional checkout locale. Defaults to `en`.
</ParamField>

## Response

### 200 OK

<ResponseField name="url" type="string">
  Stable Xquik redirect URL for the active hosted checkout session.
</ResponseField>

<ResponseField name="redirect_url" type="string">
  Same stable redirect URL in snake\_case.
</ResponseField>

```json theme={null}
{
  "url": "https://xquik.com/api/v1/credits/topup/redirect?session_id=checkout_session_id",
  "redirect_url": "https://xquik.com/api/v1/credits/topup/redirect?session_id=checkout_session_id"
}
```

### 400 Invalid input

```json theme={null}
{ "error": "Minimum top-up is $10" }
```

The top-up amount is below the \$10 minimum.

### 401 Unauthenticated

```json theme={null}
{ "error": "unauthenticated" }
```

Missing or invalid API key.

### 429 Rate limited

```json theme={null}
{
  "error": "rate_limit_exceeded",
  "message": "Too many requests. Try again later.",
  "retryAfter": 60
}
```

Too many requests. Wait for the `Retry-After` header before retrying.

<Note>
  **Related.** [Get Credits](/api-reference/credits/get) · [Get Top-Up Status](/api-reference/credits/topup-status) · [Quick Top-Up](/api-reference/credits/quick-topup) · [Billing Guide](/guides/billing)
</Note>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.