Skip to main content

Connect to OpenAI

OpenAI provides advanced AI models for natural language processing, code generation, text analysis, and reasoning tasks. You can create an OpenAI resource so you can build AI-powered apps and workflows that leverage GPT's capabilities for content generation, data analysis, conversational interfaces, and more.

What you can do with OpenAI in Retool

After you create an OpenAI resource in Retool, you can:

  • Generate, summarize, classify, and extract information from text using GPT's language models.
  • Build conversational, multi-turn chat experiences with context-aware responses.
  • Analyze images to generate captions, classify content, extract entities, or answer questions about visual content.
  • Generate images from text descriptions using DALL·E.
  • Choose between a Retool-managed key or your own OpenAI API key.

Supported models

Before you begin

Before creating an OpenAI resource, you need:

  • Retool permissions: Ability to create and manage resources in your Retool organization.
  • OpenAI API key (optional): An API key from your OpenAI account if you want to bring your own key. New Retool organizations automatically include an OpenAI resource with a Retool-managed key.

Create an OpenAI resource

Create a resource to connect Retool to OpenAI and configure authentication. Once connected, you can then select it when writing queries to make use of its available models.

Follow these steps to create an OpenAI resource in Retool.

Create a new resource

Navigate to Resources in the main navigation and click Create new > Resource and search for OpenAI. Then, click the OpenAI tile to create a new resource.

Configure connection settings

Specify a name for the resource that identifies it within your organization. Include a description that can provide more context to users and Assist about how to use the resource.

Configure authentication

OpenAI resources support two authentication options: Retool-managed keys or customer-provided keys (Bring Your Own Key).

Retool organizations include an OpenAI resource with a Retool-managed key by default. This allows you to use GPT models immediately without providing your own API key. Retool maintains a direct relationship with the AI provider and bills you directly for AI usage.

To use a Retool-managed key, set Key Source to Retool Managed.

OpenAI resource configuration with Retool-managed key
OpenAI resource configuration with Retool-managed key
Create separate API keys for Retool

Where possible, create dedicated API keys for Retool to best manage and revoke access without disruption. All API keys used with Retool are encrypted and stored securely.

Save the resource

Click Create resource to save your OpenAI resource. The resource is now available for use in apps and workflows.

Note

AI resources do not have a Test connection button. To verify your configuration, create a new app and ask the agent to test the resource for you.

Interact with OpenAI data

Once you've created an OpenAI resource, you can interact with GPT and DALL·E models using Retool.

Switch to the new app builder

Retool recommends using the new app builder so you can use natural language to build React-based apps using AI.

  • To use OpenAI models in the app builder, reference the resource in the prompt with @, such as @OpenAI. Refer to the data and functions documentation to learn more.
  • For classic apps, workflows, and agents, refer to the AI queries documentation to learn how to write a resource query.

Best practices

Follow these best practices to keep your OpenAI usage secure and cost-efficient.

Security

  • Rotate credentials regularly: Roll your OpenAI API key periodically from the OpenAI Platform, and immediately if a key is ever exposed.
  • Create separate API keys for Retool: Use a dedicated OpenAI API key for Retool so you can revoke or rotate access without disrupting other integrations.
  • Use resource environments: Organizations on an Enterprise plan can configure multiple resource environments to maintain separate OpenAI API keys for production, staging, and development.

Manage token usage and cost

  • Choose the smallest capable model: Use a faster, cheaper model (e.g. GPT-4.1 Nano) for simple tasks like classification or extraction, and reserve larger models for tasks that need deeper reasoning.
  • Set output token limits: Configure a maximum output token limit appropriate to the task to avoid paying for unnecessarily long responses.
  • Trim conversation history: For chat use cases, truncate or summarize older messages instead of sending the full history on every request. OpenAI bills for all input tokens, including message history.
  • Monitor usage: Track token consumption and spend in the OpenAI Platform usage dashboard to catch unexpected usage spikes early.