# ChatGPT for coding and canvas
Canvas gives ChatGPT a side-by-side editor where code and writing live in a persistent document you revise in place, instead of scrolling through a chat thread chasing the last good version of a function. The chat stays on the left, the artifact stays on the right, and edits land surgically: rename a variable, refactor one block, add inline comments, without regenerating the whole file. This lesson shows you how to actually work in Canvas, when to reachreachThe number of unique people exposed to your message in a given period. Unlike impressions, reach counts each person once, no matter how often they see it.View full definition → for it versus Advanced Data Analysis or Codex, and how a non-developer can read along and stay in control.
In a normal chat, every revision is a new message. The model reprints the entire script, you copy it out, and you lose the diff. Canvas turns that artifact into a living document. Ask for a change and ChatGPT edits the existing text, highlighting what moved.
Canvas opens automatically when ChatGPT decides a response is substantial code or long-form writing, or you can force it by saying "open this in canvas." Inside the editor you get:
The official overview lives in the ChatGPT Canvas help article. Read it once, then learn by building.
Let us make something concrete and genuinely useful: a script that reads a CSV of expenses and prints a category summary. Even if you do not write Python, you can drive this and verify the output.
Start in any ChatGPT conversation:
> Open a canvas. Write a Python script that reads expenses.csv with columns date,category,amount, sums the amount per category, and prints categories sorted from highest to lowest spend. Use only the standard library.
Canvas opens on the right with something like this:
import csv
from collections import defaultdict
def summarize(path: str) -> dict[str, float]:
totals: dict[str, float] = defaultdict(float)
with open(path, newline="") as f:
for row in csv.DictReader(f):
totals[row["category"]] += float(row["amount"])
return dict(totals)
if __name__ == "__main__":
totals = summarize("expenses.csv")
for category, amount in sorted(totals.items(), key=lambda kv: kv[1], reverse=True):
print(f"{category:<15} {amount:>10.2f}")Now you revise in place. This is the part that does not work cleanly in plain chat.
Select the print line inside the loop and tell Canvas:
> Also show each category's share of total spend as a percentage.
Canvas rewrites only the printing logic and the surrounding lines it needs, leaving summarize untouched. You see the change highlighted. If you dislike it, version history rolls it back.
Open the Canvas shortcut menu and pick Add comments. ChatGPT annotates the functions without you writing a prompt. Pick Add logs and it inserts logging so you can trace what the script does at runtime. These are one-click because the model already knows the document is code.
The Fix bugs action is the one to understand well. Canvas scans the current document, proposes corrections, and explains each. It is not running the code, so it reasons about likely bugs rather than observed failures. That distinction matters, and it leads directly to the next tool.
These three overlap, and choosing wrong wastes time. Here is the clean split.
Canvas is an editor. It writes and revises code and prose, but it does not execute your Python against your data. It is where you shape an artifact you will run elsewhere.
Advanced Data Analysis (the feature formerly surfaced as Code Interpreter) runs Python in a sandbox. Upload your expenses.csv, and ChatGPT executes the script, shows real output, plots charts, and catches actual runtime errors. Use it when you need results from data, not just source code. See the Advanced Data Analysis help article.
Codex is OpenAI's software engineering agent. It works across a whole repository, runs in its own environment, executes tests, and can open pull requests. It is built for real codebases and multi-file tasks, not a single snippet. Details are in the Codex documentation.
A practical workflow chains them. Draft and refine the script in Canvas. Move to Advanced Data Analysis to run it on the real CSV and confirm the numbers. Graduate to Codex when the script becomes a project with tests, dependencies, and version control.
Canvas is only as good as the constraints you give it. A few habits keep it from drifting.
State the non-negotiables in the first prompt: language version, allowed libraries, style, and target environment. "Use only the standard library" above prevented Canvas from reaching for pandas, which would have forced an install you did not want. If you skip this, expect dependencies to creep in on later edits.
If you always want type hints, docstrings in a specific format, or a particular error-handling style, put that in custom instructions so every Canvas session inherits it. For a sustained effort, work inside a Project: it keeps related chats, files, and instructions together, so the Canvas you open tomorrow remembers the conventions you set today.
Canvas does not run code, so a script can look perfect and still fail. Two cheap defenses:
1. Ask Canvas to add a tiny test or a sample input at the bottom, then move the file to Advanced Data Analysis and actually run it.
2. Use Review code to get a critique, then read the critique yourself. The model will often flag its own edge cases: empty files, missing columns, non-numeric amounts.
For our script, a good follow-up edit is:
> Handle a missing file and rows where amount is not a number. Skip bad rows and print how many were skipped.
Canvas patches summarize and the entry point without disturbing the formatting logic you already approved.
Knowledge check
1. What is the key difference Canvas introduces compared to a normal ChatGPT chat when revising code?
2. How can you explicitly force a response to open in Canvas?
3. Within the broader ChatGPT ecosystem, which tool is best suited for running and executing uploaded data files directly within the conversation?
4. Select ALL correct answers about features available inside the Canvas editor.
Sélectionnez toutes les réponses correctes.
5. Select ALL correct answers describing problems with revising code in a normal chat thread (without Canvas).
Sélectionnez toutes les réponses correctes.
A script in an editor is a draft. The path to production depends on what you are building.
If this expense summary is something you want weekly, you are not limited to running it by hand. ChatGPT supports scheduled tasks, which can trigger a prompt on a recurring basis. You can ask ChatGPT to remind you to drop in the latest CSV and rerun the analysis, turning a one-off script into a routine.
When the data does not live in a file you upload but in a connected system, Connectors let ChatGPT read from tools like cloud drives and select third-party apps, subject to your plan and admin settings. Instead of "read expenses.csv," the task becomes "summarize this month's expenses from the connected sheet." Canvas still drafts the logic; Connectors supply the live input.
Once the work outgrows a single file, hand it to Codex inside a repository, or rebuild the logic as a proper program against the OpenAI APIAPIApplication Programming Interface: a standardised interface that lets applications communicate and exchange data without knowing each other's internal workings.View full definition →. The same summarize function can sit behind a structured-output call so another system gets clean JSON instead of printed text:
from openai import OpenAI
from pydantic import BaseModel
client = OpenAI()
class CategorySummary(BaseModel):
category: str
total: float
share: float
class Report(BaseModel):
rows: list[CategorySummary]
skipped: int
resp = client.responses.parse(
model="gpt-4.1",
input="Summarize this expense data into per-category totals and shares.",
text_format=Report,
)
print(resp.output_parsed.rows[0].category)This uses the Responses API with structured outputs, so the model returns data that matches your schemaschemaA schema is the formal blueprint that defines how data is structured, named, typed, and related within a database, file, or message.View full definition → instead of free text you have to parse. Canvas is where you prototype the idea; the APIAPIApplication Programming Interface: a standardised interface that lets applications communicate and exchange data without knowing each other's internal workings.View full definition → is where it becomes a dependable component. The full reference is at platform.openai.com/docs.
You do not have to write the loop to own the result. In Canvas you read the highlighted diffs, accept or reject them, and steer with plain English: "show percentages," "skip bad rows," "explain this function in one sentence." That feedback loop is the actual skill. The model handles syntax; you handle intent, constraints, and verification.
The trap is treating Canvas output as finished because it looks clean. Clean code can be wrong code. Your job is to keep restating constraints, run the script somewhere that executes it, and read the critiques the model gives you. Do that, and Canvas becomes a fast, controllable way to produce small tools you understand, even without a coding background.