> ## 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.

# Subscribe

> Get a checkout or billing portal URL for subscription management

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

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

<Info>
  Returns a checkout URL for new subscribers or a billing portal URL for existing subscribers.
</Info>

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://xquik.com/api/v1/subscribe \
    -H "x-api-key: xq_YOUR_KEY_HERE" | jq
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://xquik.com/api/v1/subscribe", {
    method: "POST",
    headers: {
      "x-api-key": "xq_YOUR_KEY_HERE",
    },
  });
  const data = await response.json();
  // Redirect user to data.url
  ```

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

  response = requests.post(
      "https://xquik.com/api/v1/subscribe",
      headers={"x-api-key": "xq_YOUR_KEY_HERE"},
  )
  data = response.json()
  # Redirect user to data["url"]
  ```

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

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

  func main() {
      req, err := http.NewRequest("POST", "https://xquik.com/api/v1/subscribe", nil)
      if err != nil {
          panic(err)
      }
      req.Header.Set("x-api-key", "xq_YOUR_KEY_HERE")

      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. Generate a key from the [dashboard](https://xquik.com/dashboard).
</ParamField>

## Body

<ParamField body="tier" type="string">
  Subscription tier to pre-select. One of: `starter`, `pro`, `business`. If omitted, the user chooses on the checkout page.
</ParamField>

## Response

<Tabs>
  <Tab title="200 OK">
    <ResponseField name="url" type="string">Checkout URL (new subscribers) or billing portal URL (existing subscribers). Redirect the user to this URL.</ResponseField>
    <ResponseField name="message" type="string">Human-readable message describing the action taken.</ResponseField>
    <ResponseField name="status" type="string">One of: `already_subscribed`, `checkout_created`, `payment_issue`.</ResponseField>

    ```json theme={null}
    {
      "url": "https://xquik.com/billing/checkout/session",
      "message": "Complete checkout at the URL below to start your subscription.",
      "status": "checkout_created"
    }
    ```
  </Tab>

  <Tab title="401 Unauthenticated">
    ```json theme={null}
    { "error": "unauthenticated", "message": "Missing or invalid API key" }
    ```

    Missing or invalid API key.
  </Tab>

  <Tab title="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.
  </Tab>
</Tabs>

<Note>
  **Related:** [Get Account](/api-reference/account/get) to check current subscription status and usage.
</Note>
