# Code Generation (AI)

> An AI writes program code from a plain request.

**Field:** Artificial Intelligence  
**Category:** Working with AI  
**Also known as:** AI Code Generation, AI-Generated Code, Text-to-Code

## Think of it like

It is like telling a baker what cake you want. The baker does the mixing.

## Definition

Code generation is when an AI model writes program code from a plain request. You describe what the code should do, and the model writes it. It can write one function, a test or a whole small app. The model learned from huge amounts of public code. Its code often runs, but it can hide bugs or use a library that does not exist. Someone still has to read and test it.

## Example

Lucy types "a Python function that checks if a word reads the same both ways". The model writes six lines and a test.

## Why it matters

It turns hours of typing into minutes. The saved time only counts if the code is checked.

## Common mistake

Trusting code because it runs. It can pass one try and still be wrong or unsafe.

## Three principles

- **Plain request in.** Describe what the code must do.
- **Code out.** From one line to a small app.
- **Check it.** Read it and run the tests.

## Related terms

- [AI Code Completion](https://learn.benibix.com/term/ai/ai-code-completion)
- [Agentic Coding](https://learn.benibix.com/term/ai/agentic-coding)
- [AI Code Review](https://learn.benibix.com/term/ai/ai-code-review)
- [Vibe Coding](https://learn.benibix.com/term/ai/vibe-coding)
- [Large Language Model (LLM)](https://learn.benibix.com/term/ai/large-language-model)
- [AI Coding Assistant](https://learn.benibix.com/term/ai/ai-coding-assistant)

## Told apart from

- [AI Code Completion vs Code Generation](https://learn.benibix.com/compare/ai-code-completion-vs-code-generation): People think AI code completion and AI code generation are the same tool, and they are not. Completion works inside the editor while you type. It reads the code near your cursor and offers the next line or two in grey. Generation starts from a request in plain words, and the model writes a whole function, a test or a small app. Both write code you still have to read.

## Taught in

- [Code Generation and Completion](https://learn.benibix.com/learn/ai-working-with-ai/code-generation-and-completion): Prompt Engineering, 13/16

![A row of four steps: spec, generate code, review, merge. A side path skips the review step and drops into a pile marked debt, which grows under the row.](https://learn.benibix.com/diagrams/ai3-code-flow.svg)

---

Source: https://learn.benibix.com/term/ai/code-generation
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
