> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/integrations/connections/openai.md).

# Connect OpenAI to Unsloth: Run GPT Models in Local Chat

Learn how to connect OpenAI models, including GPT-5.5 to [Unsloth](https://github.com/unslothai/unsloth) so you can chat with all of them in an open-source local UI chat interface. By connecting your OpenAI API key, you can run GPT models inside Unsloth with features like [web search](#web-search-and-thinking), tool-calling, [code execution](#code-execution), [image generation](#image-generation), reusable code containers, and [prompt caching](#prompt-caching).

This guide walks you through creating an OpenAI API key, connecting OpenAI as a provider, loading available models, and troubleshooting common setup issues.

### Setup

{% stepper %}
{% step %}

#### Create an OpenAI API key

Create an API key from the [OpenAI dashboard](https://platform.openai.com/api-keys).

<figure><img src="/files/PXaINS0IoRIME98oPVwT" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Configure Connections

Next, connect your provider to Unsloth.

1. Open **Settings** → **Connections**, then click **Add Connection.**
2. Select the OpenAI, then paste the API key you copied earlier.
3. Click **Reload Models** to refresh the list with models available to your account.
4. Choose the models you want to enable, then hit save.&#x20;

<figure><img src="/files/wyW65uOZY4CSsSkvex2G" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Ready to Chat

The models you enabled will now appear under Connected in the Select Model dropdown. Supported GPT models can expose extra controls including image generation, thinking, web search and code execution.

<figure><img src="/files/Q6wnsLueufwOLm7uhaEM" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### Code Execution

When enabled, supported OpenAI models can run code in a provider sandbox to solve problems, analyse data, and work with files.

<figure><img src="/files/V90WGRM0SPKT5K6QUEQj" alt="" width="563"><figcaption></figcaption></figure>

{% columns %}
{% column width="50%" %}
OpenAI uses reusable shell containers. In **Code Execution** settings, you can set the idle timeout, create containers, select the active container, refresh the list, or delete old containers.

Select the same container in a new thread to continue with its files and state.
{% endcolumn %}

{% column width="50%" %}

<figure><img src="/files/uQSaDCf9MocZjwTlbJ2u" alt="" width="288"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

### Prompt Caching

{% columns %}
{% column width="66.66666666666666%" %}
Prompt caching reduces latency and cost when requests reuse the same long prefix. It is supported for compatible providers and servers, including OpenAI. Use the **Prompt caching** setting in the side panel to control caching behaviour for supported connections.
{% endcolumn %}

{% column width="33.33333333333334%" %}

<figure><img src="/files/QSJQ82qfp3z5H35zIou6" alt=""><figcaption></figcaption></figure>

{% endcolumn %}
{% endcolumns %}

<figure><img src="/files/rd7uqDkUz6YnddW01aRl" alt="" width="375"><figcaption></figcaption></figure>

### Web Search & Thinking

Provider-side web search is available for supported models from OpenAI. The **Think** control adapts to the selected model: some models use an on/off toggle, while reasoning-effort models use model specific thinking levels.&#x20;

<div data-with-frame="true"><figure><img src="/files/46johOqXvwqWOhGnbso4" alt="" width="563"><figcaption></figcaption></figure></div>

### Image Generation

Just like GPT, Unsloth also supports image generation. You can directly edit an image by clicking the “Edit Image” button and entering a new prompt to refine or regenerate it. Images are generated automatically when requested, but you can toggle this behavior off. A download button is also available, allowing you to save the image in its original full resolution.

<div><figure><img src="/files/tc7WCuUGdy9DA5PQwvDs" alt=""><figcaption></figcaption></figure> <figure><img src="/files/GgH0XVMZeBOPsDM3rQVv" alt=""><figcaption></figcaption></figure></div>

### Troubleshooting

If OpenAI fails to connect, check that the API key is valid and belongs to the correct OpenAI account.

If a model does not appear after clicking **Load Models**, it may not be available for your account. You can enter the model ID manually or choose another model.


---

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

```
GET https://unsloth.ai/docs/integrations/connections/openai.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.
