# Bypass Solution

## **How the Solution Works**

To bypass Castle:

1. Parse the **site key** from the webpage (starts with `pk_`).
2. Send it along with your session’s `__cuid` (if you have one).
3. Parse the response and use the `x-castle-request-token`.

### **Required Parameters**:

* `scriptID`: A numeric scriptID parsed from the page's HTML

### **Optional Parameters**:

* `__cuid`: The session’s `__cuid` cookie. If not provided, one will be generated.

It's highly recommended to provide your session’s `User-Agent`, `Sec-Ch-Ua`, and `Accept-Language` headers for more accurate token generation.

### Example Response

```json
{
  "__cuid": "...",  // Set this on your session if not provided
  "castle": "..."  // Use this token for your next request
}
```

In order to parse the scriptID from the page's HTML, you can use the following regex:

```regex
<script\s+src=["\'].*?cdn\.castle\.io/v2/castle\.js\?([^"\']+)["\'].*?>
```

{% hint style="info" %}
In order to access any of our endpoint you'll need **a valid API Key,** either [join our discord](https://takionapi.tech/discord) for a trial or [puchase a plan](https://takionapi.tech/buy)
{% endhint %}

{% openapi src="/files/GjkFPthIt43sc1jmsyil" path="/generate" method="get" %}
[castle2.yaml](https://2720813823-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fn0x4RrnIfxXvmfh6rJHh%2Fuploads%2FGmuYilyDqnjVVPVsNy66%2Fcastle2.yaml?alt=media\&token=c3d9a52a-e037-4163-b628-e5029ada9438)
{% endopenapi %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.takionapi.tech/castle/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
