# Call API

### Overview

| Field                                           | Description                                                                                                                                                  | Example                               |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------- |
| URL                                             | The URL of the API endpoint you are calling                                                                                                                  | <https://api.openai.com/v1/responses> |
| HTTP Method                                     | The HTTP method verb                                                                                                                                         | POST                                  |
| Bearer token                                    | The authentication token for your API call. Generally this is issued to you by the API service and is unique and private. Do not share this key with anyone. | sk-xyzabcdef                          |
| Request body                                    | The request body for the API call. Must be properly formatted JSON. Leave this blank for GET requests.                                                       | <p>{                                  |
| <br>"model": "gpt-4.1",                         |                                                                                                                                                              |                                       |
| <br>"input": "Give me some whale facts please!" |                                                                                                                                                              |                                       |
| <br>}</p>                                       |                                                                                                                                                              |                                       |
| Response body variable name                     | This is the variable which you can use in other nodes to process the API response body.                                                                      | gptResponse                           |

### OpenAPI (GPT) example

Example bot in action:

<figure><img src="/files/0VDlO8owC33cNokMCdlz" alt=""><figcaption><p>With this command, we'll let users ask questions to Chat GPT via our bot</p></figcaption></figure>

The following flow in BSD is used to get a prompt from the user and call Chat GPT (via OpenAI API)

<figure><img src="/files/RNkjmdQH8izXfnrIethb" alt=""><figcaption><p>Flow layout, sends a message for API success with the response</p></figcaption></figure>

<figure><img src="/files/Np354gbNAn95tsqglS2n" alt=""><figcaption><p>The get input node is used to save the text after the !gpt command to a variable. We will pass this to the API as the prompt</p></figcaption></figure>

<figure><img src="/files/uAiSqChFho6P6qqxvf2p" alt=""><figcaption><p>The Call API node is used to send the user's prompt to the API endpoint to get a response from Open AI. Make sure to enter your actual bearer token here.</p></figcaption></figure>

<figure><img src="/files/uUVNoC3iQWUtkPRju2dd" alt=""><figcaption><p>The send message node is used to send the GPT response in a message to the user.</p></figcaption></figure>

We can reference `gptResponse` since we used that variable name in the API Call node.

That's it! Now when a user uses the `!gpt` command with our bot, their prompt will be sent to OpenAI and our bot will respond.


---

# 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.discordbotstudio.org/response-nodes/external-category/call-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.
