> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://documentation.celestory.io/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# ✖️ Using Gork with X (twitter) API

To make requests to the Gork AI, you need to use the X (twitter) API.

*An API (Application Programming Interface) is a set of functionalities made available to a client/user via a library (methods of a programming language) or a web service.*
# Setting up the API

To make a request, you need an API key. It will identify who is doing what (in this case, who is using Gork). To generate a key, you can go to this [site](https://console.x.ai/), in the corresponding tab.
# Setting up Voltask

Once you have obtained the API key, you need to prepare the HTTP Request block in Voltask to send a request:
* the method is POST
* the URL is https://api.x.ai/v1/chat/completions
* the body looks like this: `{"messages": [{"role": "user","content": "{{prompt}}"}],"search_parameters": {"mode": "auto","return_citations": true,"sources": [{ "type": "web", "country": "{{country}}" },{ "type": "x"}, {"type": "news", "country":"{{country}}"}]},"model": "grok-3-latest"}`
*With* {{prompt}} *as the query sent to Gork and* {{country}} *as the ISO 3166-1 alpha-2 country code (e.g., FR for France)*
* the header looks like this: `{"Content-Type":"application/json","Authorization":"Bearer {{APIkey}}"}`
*With* {{APIkey}} *being the API key obtained earlier.*

For more details on how to fill the request body, here is the link to the documentation: [https://docs.x.ai/docs/guides/live-search](https://docs.x.ai/docs/guides/live-search)
# Retrieving the Response

The API returns a JSON object. It is necessary to select only what is important for a user.

*JSON (JavaScript Object Notation) is a textual data format used for data transmission. A JSON object is a string (text) that contains the data to be transmitted. These objects are enclosed in braces, and associate a key with a value (text, list, number, boolean value, or another JSON object), separated by colons (for example: {"fruits": ["apple", "banana"], "number": 2, "likes": true})*
## In Voltask

It is possible to start the search work from Voltask, using the [From JSON](https://documentation.celestory.io/en/article/fromjson-14l2uth/?bust=1747993992360) block. Here is a schema for retrieving information from the JSON object:

`{"$schema": "http://json-schema.org/draft-07/schema#","properties": {"choices": {"items": {"properties": {"finish_reason": {"type": "string"},"index": {"type": "number"},"message": {"properties": {"content": {"type": "string"},"refusal": {},"role": {"type": "string"}},"required": ["role","content","refusal"],"type": "object"}},"required": ["index","message","finish_reason"],"type": "object"},"type": "array"},"citations": {"items": {"type": "string"},"type": "array"},"created": {"type": "number"},"id": {"type": "string"},"model": {"type": "string"},"object": {"type": "string"},"system_fingerprint": {"type": "string"},"usage": {"properties": {"completion_tokens": {"type": "number"},"completion_tokens_details": {"properties": {"accepted_prediction_tokens": {"type": "number"},"audio_tokens": {"type": "number"},"reasoning_tokens": {"type": "number"},"rejected_prediction_tokens": {"type": "number"}},"required": ["reasoning_tokens","audio_tokens","accepted_prediction_tokens","rejected_prediction_tokens"],"type": "object"},"prompt_tokens": {"type": "number"},"prompt_tokens_details": {"properties": {"audio_tokens": {"type": "number"},"cached_tokens": {"type": "number"},"image_tokens": {"type": "number"},"text_tokens": {"type": "number"}},"required": ["text_tokens","audio_tokens","image_tokens","cached_tokens"],"type": "object"},"total_tokens": {"type": "number"}},"required": ["prompt_tokens","completion_tokens","total_tokens","prompt_tokens_details","completion_tokens_details"],"type": "object"}},"required": ["id","object","created","model","choices","usage","system_fingerprint","citations"],"title": "Generated schema for Root","type": "object"}`

However, out of all this information, only the `choices` attribute is necessary. Unfortunately, this attribute is an array and cannot be interpreted directly from the From JSON block; JavaScript will need to be used, and Celestory allows to do it.
## In Celestory

Once the `choices` array is retrieved, you can use the [Run Javascript](https://documentation.celestory.io/en/article/run-javascript-1w6p5gj/?bust=1747994016629) block to retrieve only the AI response. Here is a code that accomplishes this task:

```const raw = celestoryPoints.get("answer", "");
let answer;
try {
    answer = typeof raw === "string" ? JSON.parse(raw) : raw;
    const content = answer?.[0]?.message?.content;
    if (content) {
        celestoryPoints.set("res", content);
    } else {
        console.error("Content not found in structure:", answer);
    }
} catch (e) {
    console.error("Error parsing or accessing content:", e, raw);
}
celestoryPoints.set("res", answer[0]["message"]["content"]);
```

This way, it is possible to retrieve the AI response and use it in other blocks.
*Note that a response from the HTTP Request block may take a few tens of seconds.*