AI + Bubble.io

Using OpenAI in Bubble.io: The API Connector Setup Guide

The definitive reference for configuring OpenAI in Bubble.io’s API Connector — covering every endpoint, authentication pattern, parameter option, and common pitfall developers encounter.

5 EndpointsCovered
All Modelsgpt-4o to embeddings
ProductionReady patterns
Authentication

Setting Up OpenAI Authentication in Bubble

All OpenAI API calls require a Bearer token. Here is the exact configuration.

In Plugins → API Connector → Add another API:

  • API Name: OpenAI
  • Authentication: Private key in header
  • Key name: Authorization
  • Key value: Bearer sk-YOURKEY (mark as Private)

Add a shared header for all calls:

Content-Type: application/json

📌 Marking the Authorization header as ‘Private’ in Bubble ensures the API key is never exposed in the browser. All calls are proxied through Bubble’s server.

Endpoints

The Five OpenAI Endpoints You Will Actually Use

Each endpoint serves a different purpose. Configure each as a separate call within the same OpenAI API.

EndpointMethodUse Case
/v1/chat/completionsPOSTText generation, chatbots, summarisation, classification, Q&A
/v1/embeddingsPOSTSemantic search, similarity matching, recommendation engines
/v1/images/generationsPOSTAI image generation from text prompts (DALL·E 3)
/v1/audio/transcriptionsPOSTConvert uploaded audio to text (Whisper)
/v1/moderationsPOSTCheck user-generated content for policy violations
Chat Completions

Full Parameter Reference

Every parameter available in the chat completions endpoint and when to use each.

Required Parameters

  • model — Which model to use. Start with gpt-4o-mini for cost efficiency.
  • messages — Array of message objects with role and content fields.

Optional but Important

  • max_tokens — Cap on response length. Set this always to control costs.
  • temperature — Randomness (0-2). 0 = deterministic, 1 = balanced, 2 = very creative.
  • response_format — Set to {“type”:”json_object”} for structured JSON output.
  • stream — Set true for streaming responses (requires special Bubble handling).

For structured output (making the AI return valid JSON), use this body pattern:

{
"model": "gpt-4o-mini",
"response_format": { "type": "json_object" },
"messages": [
{
"role": "system",
"content": "You respond only in valid JSON with this structure: {'category': string, 'confidence': number}"
},
{ "role": "user", "content": "" }
]
}
Embeddings

Setting Up Semantic Search in Bubble

Embeddings let you find the most relevant database records for any user query — far more powerful than keyword search.

1

Generate embeddings for your content

For each record in your database (articles, products, FAQs), call /v1/embeddings with the text content and model text-embedding-3-small. Store the returned embedding (a large array of floats) in a long text field.

2

Generate an embedding for the user query

When a user searches, call the same embeddings endpoint with their search query. You now have a numeric vector representing their intent.

3

Calculate cosine similarity in a backend workflow

Loop through your database records, calculate cosine similarity between the query embedding and each record’s stored embedding, and return the top N results sorted by similarity score.

4

Display relevant results

Populate a Repeating Group with the top matched records. Users see semantically relevant results even when they use different words than your content does.

Common Pitfalls

Errors You Will Encounter and How to Fix Them

ErrorCauseFix
401 UnauthorizedAPI key missing or incorrectVerify the Authorization header value starts with ‘Bearer sk-‘
429 Rate LimitToo many requests per minuteAdd exponential backoff retry logic in your workflows
400 Bad RequestMalformed JSON in request bodyCheck that all dynamic parameters are populated before the API call
Context length exceededConversation history too longTrim the messages array to the last N turns before sending
Empty responsemax_tokens too lowIncrease max_tokens; the model cut off mid-response

Need Help With Your OpenAI + Bubble.io Integration?

SA Solutions specialises in production-grade Bubble.io AI integrations. We have solved every error above (and more) across dozens of client applications.

Book a Technical CallOur AI Services

Simple Automation Solutions

Business Process Automation, Technology Consulting for Businesses, IT Solutions for Digital Transformation and Enterprise System Modernization, Web Applications Development, Mobile Applications Development, MVP Development