Mastering Generative AI with OpenAI

Building an Interactive Chatbot

Word Completion vs Chat Completion

Before integrating a chatbot into your application, it’s essential to understand the difference between word completion and chat completion. Although both use the same underlying GPT-3.5-Turbo model, their usage patterns—and the way they manage context—are very different.

What Is Word Completion?

Word completion is a stateless API call. You send a single prompt, and the model returns a continuation without retaining any memory of previous interactions.

Key characteristics:

  • Single-shot responses
  • No conversation history
  • Simpler, lower token usage

The image compares "Word Completion" and "Chat Completion," highlighting that word completion doesn't need memory, while chat completion expects context from previous conversations.

What Is Chat Completion?

Chat completion is stateful. You maintain a record of all messages in a messages array, allowing the model to build on past user and assistant exchanges.

How Chat Completion Works

  1. You create an ordered messages list.
  2. Each entry has a role: system, user, or assistant.
  3. You submit the full history each time you call the API.
  4. The model returns a response that accounts for all previous context.

Roles in the messages Array

RoleDescriptionExample
systemSets global instructions or persona“You are a physics professor.”
userRepresents the human’s input at each turn“Explain quantum mechanics in simple terms.”
assistantModel-generated responses that continue the conversation context“Quantum mechanics is the study of matter at very small scales…”

The image illustrates the difference between word completion and chat completion, showing a user interacting with a system and an LLM (Large Language Model) using chat history as a message parameter.

When to Use Each API

  • Use word completion for simple text continuations, code generation, or single-turn tasks.
  • Use chat completion for multi-turn conversations, contextual assistants, and applications that require stateful interaction.

Sample Chat Completion Request

POST https://api.openai.com/v1/chat/completions
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY

{
  "model": "gpt-3.5-turbo",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user",   "content": "Explain photosynthesis." }
  ]
}

Comparison at a Glance

FeatureWord CompletionChat Completion
Context HandlingStatelessStateful via messages array
Best forSingle-turn promptsMulti-turn conversations
Token EfficiencyFewer overhead tokensMore overhead tokens for history
Recommended ModelGPT-3.5-TurboGPT-3.5-Turbo

Further Reading and References

Watch Video

Watch video content

Previous
Section Intro