← Blog

Build AI Apps with ChatGPT, DALL-E, and GPT-4

2026-09-20 · 5 min read · SubToAPI Team

Building an AI app "with ChatGPT, DALL-E, and GPT-4" almost always means one thing in practice: calling OpenAI's API from your own backend and combining a few endpoints — chat/completions for reasoning and conversation, image generation for visuals, and sometimes function calling for structured actions. ChatGPT itself is a product you talk to in a browser; the thing you actually build apps against is the underlying API, where GPT-4 (or GPT-4o/GPT-4-turbo) handles text and DALL-E handles images.

This guide covers the concrete pieces you need: getting API access, choosing an architecture, wiring text and image generation together, and managing cost and reliability once real users show up. It also covers where a second model provider fits in, since most production apps end up multi-model rather than single-vendor.

What "ChatGPT, DALL-E, and GPT-4" actually means for developers

These three names map to specific API surfaces:

An app that "uses ChatGPT, DALL-E, and GPT-4" is really an app that sends text prompts to a chat endpoint and image prompts to an image endpoint, then stitches the outputs together in your UI — a chatbot that can also generate a picture when asked, a content tool that writes copy and produces matching graphics, a product mockup generator, etc.

The minimal architecture

Almost every working version of this app has the same shape:

  1. Frontend — chat UI or form that collects the user's request.
  2. Backend — a server that holds the API key, decides which model to call, and formats the request.
  3. Model calls — chat completions for text, image generation for visuals.
  4. Storage — conversation history, generated image URLs, usage logs.

Never call the model API directly from client-side JavaScript in production — your API key would be exposed in the browser. Route everything through your own backend.

A basic text generation call looks like this:

const response = await fetch("https://api.openai.com/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.OPENAI_API_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "gpt-4o",
    messages: [{ role: "user", content: "Write a product tagline for a coffee subscription." }]
  })
});

And an image generation call follows the same pattern, just against the image endpoint with a prompt describing the desired output instead of a conversation.

Combining text and images in one flow

The pattern that shows up most often — a marketing copy generator that also produces a hero image, a recipe app that writes instructions and illustrates the dish, a children's story app that generates both text and pictures — is a two-step pipeline:

  1. Ask GPT-4 to write the content and, optionally, a short image prompt describing what the accompanying visual should look like.
  2. Feed that image prompt into the image generation endpoint.
  3. Return both the text and the image URL to the frontend together.

Letting GPT-4 write its own image prompt (rather than passing the user's raw text to the image model) usually produces noticeably better images, because the model can translate a vague user request into a detailed visual description.

Handling structured actions with tools

Once your app needs to do more than generate text and images — look up a database, call a payment API, fetch live data — you need function/tool calling. Instead of parsing free text for intent, you define a schema and let the model return a structured call:

{
  "name": "generate_image",
  "description": "Generate an image from a text prompt",
  "parameters": {
    "type": "object",
    "properties": { "prompt": { "type": "string" } },
    "required": ["prompt"]
  }
}

The model decides when to invoke it, your backend executes it, and the result gets fed back into the conversation. This is the mechanism that turns a chatbot into an agent that can actually take actions.

Managing cost and reliability at scale

Two things bite every team that ships one of these apps past the prototype stage:

If your team already pays for Claude access and wants the same "API key from a subscription" pattern OpenAI offers, SubToAPI does that for Claude specifically — it turns your existing Claude plan into an HTTPS API with sub_live_ application keys, streaming responses, tool use, usage metadata per key, and team seats in one dashboard. It's not a ChatGPT or DALL-E replacement, but it's a straightforward way to add Claude as a second model in a multi-provider app without asking every teammate to manage their own separate API billing. Setup follows the same shape as the OpenAI flow above — see the quickstart and the messages endpoint docs for the exact request format, and pricing for plan details.

A practical build order

  1. Get API access and confirm billing limits before writing code.
  2. Build the text pipeline first — a single chat completions call, working end to end.
  3. Add image generation as a second, independent call.
  4. Combine them into one user-facing flow (text generates the image prompt, image call runs second).
  5. Add tool calling only once you have a concrete action the model needs to trigger.
  6. Add logging, per-user rate limits, and a fallback model before opening it to real users.

questions

Do I need separate API keys for ChatGPT, DALL-E, and GPT-4? No. GPT-4 and ChatGPT use the same OpenAI API key against the chat completions endpoint; DALL-E uses the same key against a separate image endpoint. It's one account, two endpoints.

Can I build this without a backend server? Not safely for production. Client-side calls expose your API key. A thin backend that holds the key and proxies requests is the minimum viable setup.

Should I use only one model provider? For a prototype, yes — it's faster. For production, most teams add a second model as a fallback or for specific tasks, since a single-provider outage otherwise takes the whole app down.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →