# How to Build an AI Media Buyer With Claude Code

> You can build an AI media buyer with Claude Code inside Antigravity by describing what you want, approving a plan, then adding your Meta credentials to an environment file. The agent then reads your ad account and creates campaigns, ad sets and ads from plain language requests. The build needs no hand written code.

Source: https://fluxomate.com/blog/build-a-media-buyer.html  
Published by Fluxomate (https://fluxomate.com/), 2026-04-24. Section: Claude Code builds.
Video: https://www.youtube.com/watch?v=wJ5iH8CocDY

## Key takeaways

- The build uses Antigravity as the coding environment and Claude Code as the agent.
- Start in plan mode: describe the agent, review the plan, then let it build.
- Credentials go in an environment file: Meta app ID, secret, ad account ID and an access token.
- The agent debugs itself when a call fails, so you mostly approve and answer questions.
- Treat it as a proof of concept and review security before anyone relies on it.

## What is an AI media buyer and why build one?

An AI media buyer is an agent with direct access to your ad account. It can create campaigns, create ad sets, create individual ads and read the data in the account, all from plain language instructions. In this build it lives in the terminal, so there is no interface to design.

The point is not to replace people. It is to increase output for the same input, so a team can take on more clients without hiring more. Creating two ads by hand takes minutes, but the value appears when you need to create many ads at once, using different ad sets, interest targeting and creative files.

This is a proof of concept. It is the simplest version of the system, and we recommend improving it rather than copying it exactly.


## What do you need to get started?

- Antigravity, a coding environment from Google. Download the version for Windows or Mac.
- A paid Claude plan. Claude Code needs one.
- Claude Code, installed by copying the install command from the Claude Code page and running it in your terminal.
- The Claude Code extension in Antigravity, from the extensions panel. Antigravity defaults to Gemini, but we use Claude Code.
- A Meta business account with an ad account to connect.
- Optionally, a voice dictation tool so you can speak your prompts.

## How do you set up the project?

Everything lives in folders. Create a main folder for your projects, then a folder for this agent, for example media buyer. Open that folder in Antigravity. Files the agent creates will appear on the left, and the chat with Claude Code sits on the right.

You do not touch any code. The AI writes and edits all of it.


## How do you write the first prompt?

Switch Claude Code to plan mode. Claude has modes for planning, asking before edits and editing automatically. Use planning first so you can check the approach.

Then describe the agent. The prompt in this build asked for a terminal based AI agent called Media Buyer that controls a Meta Ads account. It should use the Anthropic SDK with tool calling, have separate skills in the folder structure, create campaigns, create individual ads, pull data from ads and show which ads are running. It also asked for a plan, with the focus on skills instead of any user interface.

Claude checks the folder, may run web searches, then returns a plan. In this build the plan covered the architecture, a file structure with an agent folder and a skills folder, tools such as getting account info, creating and updating ad sets, an environment file for keys, requirements, safe defaults and an implementation order. If the plan looks right, approve it and choose auto accept. It then builds the files while you watch.


## How do you connect the agent to your Meta ad account?

Once the files exist, ask Claude to give you step by step instructions for the API keys and to create the environment file. This is the most time consuming part. Follow the instructions and paste each value into the file.

1. Anthropic API key: create one in your Anthropic account. In this build it was added for completeness, since the agent was being run from the terminal.
2. Meta ad account ID: open Ads Manager and read the account ID from the page address.
3. Create a Meta app on the Meta developers site. Choose the option to create and manage ads with the Marketing API, and connect it to your business portfolio.
4. Copy the app ID from the app settings and the app secret from the basic settings.
5. Generate an access token in the Graph API explorer. Select your app and add the ads management and ads read permissions.
6. Tell Claude the variables have been added and ask it to test whether it can access the ads.

## What happens when something breaks?

Expect errors. In this build the first test hit a deprecated call and an invalid API request. Claude read the error, worked out the problem, updated its code and ran an end to end test. You do not have to debug it yourself, which is a big difference from a no code workflow.

When the test succeeded, the agent read the campaign data from the real ad account. Next came a request to create a campaign called Testing YouTube. The first attempt failed, Claude fixed its own skill, and the campaign appeared in Ads Manager.


## How do you create ad sets and ads?

Ask for a specific build. In this example the instruction was to create two ad sets in the new campaign, with the same ad running in both, and to write the primary text, headline and other copy based on what Claude knew about the offer. A creative file was attached by pasting its file path.

Claude asked follow up questions, such as the website, the daily budget, the targeting split and the Facebook page ID. The answers were a broad ad set and an interest ad set, so the two could be split tested. When it finished, Ads Manager showed the campaign, the two ad sets, two ads with the creative, a link, a headline and a call to action. The primary text was missing, which can be fixed by asking Claude to add it.

Once it works, you can also ask the agent questions about the account, such as ad spend over the past seven days or the best performing campaigns.


## What should you watch out for?

Security matters. There is not much built in, so know what is happening. Have the code base reviewed, for example by a separate agent, before it becomes more than a local tool. Be careful when publishing a Meta app and when giving anything access to your ad accounts.

Watch the context meter in Claude Code. As the conversation grows, the context fills up and performance can drop. Claude compacts the history automatically, but keep an eye on it. You can also run two instances at once, although that uses more credits.


## Questions people ask

### Do I need to know how to code to build an AI media buyer?

No. In this build Claude Code wrote and fixed all the code. The only manual step was adding the credentials to an environment file.

### What does the AI media buyer do?

It connects to your Meta ad account and can create campaigns, ad sets and ads, and read the data in the account, based on plain language requests.

### What credentials does it need?

A Meta app ID, a Meta app secret, your ad account ID and an access token with ads management and ads read permissions. An Anthropic API key was also added to the environment file.

### Is this ready for production use?

No. It is a proof of concept. Improve the prompts, add structure and check the security before relying on it.

Tools used: Claude Code, Antigravity, Meta Ads Manager, Meta Marketing API, Anthropic API

Free templates for this guide: https://fluxomate.com/resources.html?r=build-a-media-buyer
