> For the complete documentation index, see [llms.txt](https://ruilabs.gitbook.io/airgent/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ruilabs.gitbook.io/airgent/agent/using-chatgpt-node-in-your-agent.md).

# Using ChatGPT node in your agent

## **Prerequisites**

Before you begin, ensure you have:

1. An **API Key** from the [OpenAI platform](https://platform.openai.com/docs/quickstart).
   * You can follow OpenAI's official guide to get your API key

***

## **Step-by-Step Guide**

The final agent is setup as below:

<figure><img src="/files/RfPDZh3UsGJ1SwhRi5N9" alt=""><figcaption><p>Agent integrated with ChatGPT node</p></figcaption></figure>

{% stepper %}
{% step %}
**Add the ChatGPT Node**

1. From the **Node Library** on the left panel, expand the **Llm** section.
2. Drag the **ChatOpenAI** node onto your workspace.
   {% endstep %}

{% step %}
**Configure the ChatGPT Node**

1. **API Key**:
   * Paste your OpenAI API key into the `apiKey` field of the node.
   * This key authenticates your requests to OpenAI’s servers.
2. **Model Name**:
   * The default model is `gpt-4` (or `gpt-3.5-turbo` if you prefer).
   * Specify the model in the `modelName` field.
3. **Temperature** (Optional):
   * This controls the randomness of the AI’s responses.
   * A value of `0` gives deterministic responses, while higher values introduce more variability.
4. **Schema**:
   * For our example, the schema can be ignored since we’re working with a simple string input.
5. **Error Handling**:
   * We’re skipping error handling for now, but this can be added later to manage API errors.
     {% endstep %}

{% step %}
**Connect the Nodes**

1. **Execution Flow (Exec)**:
   * Connect the `exec` port of the **Input Node** to the `exec` port of the **ChatOpenAI** node.
   * Then, connect the `exec` port of the **ChatOpenAI** node to the `exec` port of the **Output Node**.
2. **Message Flow**:
   * Connect the `message` port of the **Input Node** to the `message` port of the **ChatOpenAI** node.
   * Finally, connect the `response` port of the **ChatOpenAI** node to the `message` port of the **Output Node**.
     {% endstep %}

{% step %}
**Test Your Agent**

1. Use the **Message Box** at the bottom-right to send a message (e.g., “Hi”).
2. Observe the response:
   * Your input message is processed by the **ChatGPT Node** and returned through the **Output Node**.
   * For example, if you type “Hi,” you might receive “Hello! How can I assist you today?”
     {% endstep %}
     {% endstepper %}

***

## **What’s Next?**

By integrating the ChatGPT Node, your agent can now handle conversational input and provide intelligent, context-aware responses. Let’s move forward to building more advanced workflows!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://ruilabs.gitbook.io/airgent/agent/using-chatgpt-node-in-your-agent.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
