# OpenAI

> This page is about FlutterFlow (the app builder you use by describing your app), not FlutterFlow Studio.

URL: https://docs.flutterflow.io/ffx/openai

Connect your OpenAI API key, and then ask the agent for a feature that answers in text with an OpenAI model, billed to your OpenAI account.

Add a feature that sends a request to an OpenAI model and shows the written answer, such as a summary, a suggestion, or a reply. You need an API key from the OpenAI dashboard.

## Connect a key {#connect-your-key}

To connect OpenAI, you must be a project owner. Everyone who can change the app can use OpenAI after an owner connects it. Create an API key in the OpenAI dashboard under API keys. The key starts with `sk-`, and a project key works.

1. Open **Project Settings › Connections**.
2. Turn on the switch for **OpenAI**. On a phone, tap **OpenAI**. The **Connect OpenAI** dialog opens.
3. Connect a key in one of these ways:
   - To reuse a key from another of your apps, click **Use the key from** that app. OpenAI connects at once.
   - To use a new key, click **Paste an API key** if the dialog shows it, paste your key into **API key**, and then click **Connect**. To open the OpenAI API keys page, click **Find it** beside the label.

OpenAI checks the key before FlutterFlow saves it, and FlutterFlow never shows the key again.

## Cost and model {#cost-and-model}

Every AI call that your app makes is billed to the provider account that the key belongs to.

Your app's AI calls use the model and the response length that the feature is built with, and people who use your app can't change them. Name both in your request:

- **Model:** each call's cost depends on the model. To see the models that you can name, ask the agent to list them, and then pick one.
- **Response length:** the longest answer that each call pays for. When an answer reaches it, the service stops, even in the middle of a sentence.

## What to ask

To ask for an OpenAI feature, tell the agent what the feature does, that it uses OpenAI, which model it uses, and how long its answers can be. Replace [model name] with a model that the agent lists for your key:

> Example request: "Which models can my connected OpenAI key use?"

> Example request: "Add a monthly summary to the budget screen that asks OpenAI to describe my spending in about 150 words. Use [model name]."

> Example request: "On each transaction, add a Suggest a note button that asks OpenAI for a short note based on the payee and the amount. Use [model name], and keep each answer to one sentence."

## Agent questions {#what-the-agent-may-ask-you}

If OpenAI isn't connected, the agent asks you to connect it, with a **Connect OpenAI** button that opens the same dialog. If you aren't a project owner, ask one to connect OpenAI. For more information, see [Connect a service](https://docs.flutterflow.io/ffx/connect-a-service).

## Review {#check-the-result}

After the agent finishes, read the turn's [**Summary**](https://docs.flutterflow.io/ffx/what-changed#summary) and review its [**Changes**](https://docs.flutterflow.io/ffx/what-changed#changes-tab). Check the affected screens in **Screens**, and try the change in **Preview**. If the change uses records or sign-in, test it with [the thread's own data in **Data**](https://docs.flutterflow.io/ffx/thread-data).

After you push a backend change, check the result in **Backend**.

Try the feature in the preview a few times and read the answers.

## Push {#push-it}

After you test the feature, [push the changes to your app](https://docs.flutterflow.io/ffx/push).

## Next steps {#then}

- To replace the key or disconnect OpenAI, see [Manage connections](https://docs.flutterflow.io/ffx/manage-connections).
- To see the other services that you can connect, see [Services](https://docs.flutterflow.io/ffx/services).

## Troubleshooting {#if-something-goes-wrong}

- **OpenAI refuses your key:** see [A service refuses your key](https://docs.flutterflow.io/ffx/troubleshoot-connections#key-refused).
- **The dialog says that your key looks like an Anthropic or OpenRouter key:** OpenAI keys start with `sk-`, but not `sk-ant-` or `sk-or-`. Connect that key as [Anthropic](https://docs.flutterflow.io/ffx/anthropic) or [OpenRouter](https://docs.flutterflow.io/ffx/openrouter) instead, or create an OpenAI key.
- **The dialog says that OpenAI API keys start with `sk-`:** the key isn't a whole OpenAI key. Copy the whole OpenAI key from the OpenAI dashboard, and paste it again.
- **Calls stop working after you delete or rotate the key:** create a new key in the OpenAI dashboard, and then [replace the key](https://docs.flutterflow.io/ffx/manage-connections#replace-key).
- **Answers stop in the middle of a sentence:** the response length is too short for the model. Ask the agent for a longer response length.
- **A call fails without any answer:** a reasoning model can use up the response length before it returns any text. Ask the agent for a longer response length. If the response length is already at its longest, ask the agent for a different model.
- **OpenAI declines a prompt:** trying the same prompt again usually doesn't help. Change the prompt.
- **A call takes too long and fails:** OpenAI answers sooner with a shorter response length. Ask the agent for a shorter one, and try again.
- **Calls fail because the account is out of credit:** add credit, or raise your spending limit, in the OpenAI dashboard, and then try again.
- **Calls fail because of rate limits:** FlutterFlow limits how often one connection can be called each minute, so wait a minute and try again. If the message says that OpenAI is rate limiting requests, OpenAI's own limit was reached. Wait as long as the message says, and then try again.
- **Your app shows a message about the service:** see [Messages shown in your app](https://docs.flutterflow.io/ffx/troubleshoot-connections#app-messages).
