Generative AI

AI Agents with Python: OpenAI, Claude and Grok

Program Python agents that run on your computer with the OpenAI, Claude and Grok APIs: learn to buy tokens, calculate and cap what you spend, and build agents that prepare Excel files, Word reports, presentations, LinkedIn and TikTok content and your weekly routine.

Beginner · 25 hours · 29 lessons · Course language: Spanish and English

A hands-on generative AI course with Python and only three official APIs: OpenAI (GPT), Anthropic (Claude) and xAI (Grok). Your agents run on your computer and use the official openai and anthropic SDKs. You start without spending anything: the project includes a rehearsal mode that mimics the three APIs, so you learn the whole flow before you buy. Then you buy the minimum credit in each console step by step, turn off auto-recharge, set spending caps and store your keys safely. You learn what a token is, how to count it and what each call costs at the official prices, and you work out an agent's monthly budget. You program system instructions, memory, validated JSON output, streaming and error handling, with one codebase for all three providers. You build an agent loop with tools (function calling and tool use), with a step cap, a spending cap, a cost log and human approval for actions with side effects, and you protect it from injected instructions. With the data of Café Kallpa, a fictional coffee-shop chain, you create agents that deliver Excel files with formulas and charts, Word reports, PowerPoint decks, LinkedIn and TikTok content in the brand's voice and campaign and social media analysis, and you schedule a routine that prepares every Monday's package. In the advanced module your agents read PDF contracts, turn photographed invoices into checked data, search the web with cited sources, answer with company policies, work as a team with different roles and providers, process hundreds of comments with the batch APIs and go live as a web page for your team. You finish by comparing GPT, Claude and Grok with your own tests and delivering your office agent with its cost report. The lessons, quizzes and videos are in English; the course project's code keeps its original Spanish names, and every lesson explains them.

What you will learn

  • Buy API credit at OpenAI, Anthropic and xAI with spending caps, and store the keys safely
  • Count tokens and calculate each call's cost and an agent's monthly budget
  • Program with the official SDKs: instructions, memory, validated JSON, streaming and errors
  • Use one codebase for GPT, Claude and Grok and switch provider from the configuration
  • Build agents with tools, a step cap, a spending cap and human approval
  • Create agents that deliver Excel files with formulas, Word reports and PowerPoint decks
  • Generate LinkedIn and TikTok content in the brand's voice and analyze campaigns and social media
  • Schedule a weekly routine and choose a provider with tests of accuracy, cost and time
  • Read PDF contracts and photographed invoices, checking every figure with Python
  • Search the web with cited sources and answer with the company's policies
  • Coordinate teams of agents, process in batches and publish your agent as a web page

Skills

Python, OpenAI API, Claude API, Grok API (xAI), AI agents, Function calling, Tokens and costs, Buying API credit, Structured output, Excel with openpyxl, Word with python-docx, PowerPoint with python-pptx, AI for marketing, LinkedIn and TikTok, Routine automation, Agent security, PDFs and images with AI, Web search with sources, RAG over company policies, Multi-agent systems, Batch APIs, Web app with Python

Program

Module 1: Start here

Your Python environment, buying tokens with caps, and your first call to the three APIs.

Project: The course project running in rehearsal mode and one real call with its cost worked out.

  1. Agents on your computer with Python: what you'll build: Install Python and the course project, and run your first agent in rehearsal mode.
  2. Buy your tokens: prepaid credit at OpenAI, Anthropic and xAI: Developer accounts, minimum purchase, auto-recharge, spending caps and keys in .env.
  3. Your first call to the three APIs and what it cost: The same question to GPT, Claude and Grok with their official SDKs, and its cost worked out by hand.

Module 2: Tokens and costs

Count tokens, calculate costs, budget a month and spend less.

Project: An agent's monthly budget for a task from your job.

  1. What a token is and how to count it before you pay: The 4-character rule, Claude's count_tokens and each API's real usage.
  2. Your cost calculator and the monthly budget: Official prices, the cost of a month of work and the long-request trap.
  3. Spend less: the right model, caching, batches and limits: How much each decision saves, measured with the calculator.

Module 3: Programming the three APIs

Instructions, memory, validated JSON, streaming, errors and shared code.

Project: A message classifier that works the same with GPT, Claude and Grok.

  1. System instructions and conversations with memory: The assistant's role and a history your program sends again.
  2. Structured data: JSON your program can use: A JSON schema to classify customer messages on all three providers.
  3. Live answers and errors: streaming, retries and limits: Text that appears as it is written, and what to do with each error.
  4. One codebase for three providers: preguntar() hides each SDK's differences and compares cost and time.

Module 4: Your first agent

Tools in each API, the loop with caps, and the agent's security.

Project: An analyst agent with a spending cap and human approval to send emails.

  1. Tools in OpenAI and Grok: the model asks, Python runs: function_call, function_call_output and previous_response_id step by step.
  2. Tools in Claude: tool_use and tool_result: The same tools with Claude's API, and how to return errors.
  3. The agent loop with step and spending caps: An agent that uses several tools and logs the cost of each call.
  4. Security: human approval, injected instructions and keys: Actions that wait for your approval, rules the model can't change and protected keys.

Module 5: Office agents: Excel, Word and PowerPoint

Figures calculated by Python and office files created by the agent.

Project: An Excel file with formulas, a Word report and a presentation with checked figures.

  1. Excel analyst agent: figures calculated by Python: An Excel file with SUMIFS formulas and a chart that recalculate on their own.
  2. Word report agent: Paragraphs written by the model and a table with the tools' figures.
  3. PowerPoint presentation agent: Titles that conclude, bullets and speaker notes with ROAS, CPA and CTR.

Module 6: Marketing and routine agents

LinkedIn and TikTok content, campaign and social media analysis, and the weekly routine.

Project: Monday's package prepared and scheduled to run on its own.

  1. LinkedIn and TikTok content agent with your brand voice: One idea adapted to each network, checked by rules in code before publishing.
  2. Campaign and social media agent: ROAS, engagement and comments: A marketing analysis with three tools that recommends without acting.
  3. Your automatic weekly routine: the agent that works every Monday: Monday's package with a spending cap, scheduled on Windows or macOS.

Module 7: Quality and final project

Compare providers with tests and deliver your office agent.

Project: Your agent with its spec sheet, tests passed in real mode and a cost report.

  1. Compare GPT, Claude and Grok with your own tests: Accuracy, cost and time to choose a provider with data.
  2. Final project: your office agent with a budget and tests: Your agent's spec sheet, spending cap, automated tests and cost report.

Module 8: Advanced agents

PDFs, images, web search, policies with citations, teams of agents, bulk processing and a web app.

Project: A checked contract and invoice, a policy assistant with citations, a team of agents and your agent published on a page for the team.

  1. PDF contracts: the agent extracts, Python calculates the dates: A supplier contract turned into a sheet of 11 checked facts, its key dates and its risks.
  2. Photographed invoices to data that adds up: Vision on the three APIs and a check of lines, IGV and total before recording.
  3. Web search with cited sources and what it costs: Each API's search tool, its citations and what every search costs.
  4. An assistant for the company's policies that cites its sources: Search, read and cite in your documents, and say "it's not there" when it isn't.
  5. A team of agents: writer, reviewer and fact checker: Roles with different providers, structured outputs, a round cap and cost per role.
  6. Bulk processing: in parallel, resumable and in batches: Hundreds of comments without paying twice, and the batch APIs at half price.
  7. Your agent on a web page for the team: A Python server, an access key, a cap per question and the model's text always escaped.

Prerequisites

  • Basic Python: variables, lists, dictionaries, functions and loops (the free Python from scratch course is enough).
  • A Windows or macOS computer where you can install Python 3.12 and Visual Studio Code.
  • For real mode: a card that accepts online purchases in US dollars. With USD 5 at a single company you can do the whole course; lessons 1 and 3 to 29 also work in rehearsal mode, without paying anything.

Next courses

  • Agentic AI: From Workflows to Autonomous Agents · Advanced · 32 hours
    The difference between an agentic system and an agent, and the best practices for building both: workflows, the agent loop, tools, context engineering, skills, MCP, code execution, human in the loop, durable execution, evaluation, observability, security and production. Theory and a lab in every class, 24 labs verified in Docker with the official documentation, and a video in every class.
  • Coding Agents with Codex and Claude · Advanced · 25 hours
    Program with AI agents like a professional team: Claude Code, OpenAI Codex and your own agents with the Claude Agent SDK.

See all courses