# How to Get Meta Ads API Credentials for an AI Agent

> To give an AI agent access to Meta Ads you need four Meta details plus an AI key: an ad account ID, an app ID, an app secret and an access token. You create a Meta app with the Marketing API permission, generate a token with ads management and ads read permissions, and store everything in the project's environment file.

Source: https://fluxomate.com/blog/how-to-get-meta-ads-api-credentials-for-an-ai-agent.html  
Published by Fluxomate (https://fluxomate.com/), 2026-04-24. Section: Claude Code builds.
Video: https://www.youtube.com/watch?v=wJ5iH8CocDY

## Key takeaways

- Ask Claude Code for step by step instructions and have it create the environment file for you.
- The credentials are an AI key, a Meta ad account ID, an app ID, an app secret and an access token.
- The app needs the permission to create and manage ads with the Marketing API.
- The access token needs ads management and ads read permissions.
- Test with a read request first, then create something small, and check it in Ads Manager.

## What credentials does an AI Meta Ads agent need?

The agent in the video is a terminal based media buyer. You type a natural language request, Claude works out what to do, and Python code runs the matching call against the Meta Marketing API. It can create campaigns, create ads, pull data and show what is running.

Once Claude had built the files, we asked it for specific instructions on the keys it needed and asked it to create the environment file. This is the file where the keys are stored. It came back with a checklist of five items:

1. An AI key from Anthropic.
2. Your Meta ad account ID.
3. A Meta app ID.
4. A Meta app secret.
5. A Meta access token.

## How do you get the two easy keys?

Start with the easy ones. For the AI key, sign in to the Anthropic console, add credits if your account asks for them, choose to get an API key, give it a name and create it. Copy it and paste it into the environment file. The key is not strictly needed for a tool run from the terminal, but we added it to show the full process.

For the ad account ID, open Ads Manager. The account ID is in the page address, so copy it from there and paste it into the file.


## How do you create the Meta app?

This part is harder. The app is what gives the agent permission to use your ad account, so follow the instructions Claude gives you.

1. Go to Meta's developer site and log in. Create an account if you do not have one.
2. Create a new app from scratch and give it a name and a contact email.
3. Choose the use case that lets you create and manage ads with the Marketing API. This is a bundle that includes the access needed, and you do not need the rest.
4. Connect your business portfolio. You may be asked for a password and two factor authentication code, because the app is tied to the business account.
5. When the app exists, follow Claude's steps: choose the other business option and give it a name.
6. In the app dashboard, open settings and then basic. Copy the app ID and paste it into the environment file.
7. On the same basic settings page, copy the app secret and paste it in.

## Should you publish the app?

In the video the app was published, which needed a privacy page link, and a system user was part of the plan. We were relaxed about it because we had done it before. Be more careful. Publishing an app and giving it access to ad accounts is a real decision, so do not do it carelessly, and only connect accounts you mean to connect. Never paste keys anywhere you should not. The ones shown on screen were deleted afterwards.


## How do you generate the access token?

The token is the last credential, and the fiddliest. Claude's instructions point you to Meta's Graph API Explorer. Open it and select your app from the list. Choose to get an access token, and add permissions. The two you need are ads management and ads read.

Generate the token, confirm when Meta asks you to continue as your account, then copy it and paste it into the environment file. Our own run needed a little trial and error to find the right options, and the token flow had changed since the last time we set it up, so expect some friction.


## How do you test the connection?

Tell Claude the environment variables are in the file and ask it to test the system and see if it can access the ads. It reads the file, confirms the credentials are present and runs a test command.

The first attempt hit a warning. A call the code used was out of date, and Meta rejected it as invalid. You do not fix this yourself. Claude reads the error, works out the cause, updates the code and runs an end to end test with a real prompt, in this case asking for all campaigns. This time it returned real data, and the numbers matched what Ads Manager showed.

Now try a small write. We asked it to create a test campaign. The first call errored, Claude corrected its own skill and tried again, and the campaign appeared in Ads Manager after a refresh. Meta can be slow to update, so reload before you assume something failed.


## How do you create ad sets and ads with the agent?

Ask Claude to create two ad sets inside the new campaign, with the same ad running in both, and to ask you the questions it needs. Tell it to write the primary text and headline for you. Attach a creative by copying the file path of an image, because the agent can read files on your computer.

It asked about targeting, budget and your Facebook page ID. We chose one broad ad set and one interest ad set, so the two could be split tested, and gave a daily budget. For the page ID we took a screenshot and pasted it into the chat.

The result was two ad sets and two ads in the campaign, each with the creative, a link and a call to action. Some copy was missing, and the link was not the right one. Those are fixed by prompting again. The same set up could create many ads from a list of creatives and targeting options, and you can also ask it questions about spend and the best performing campaigns.


## Questions people ask

### Where do I find my Meta ad account ID?

Open Ads Manager and look at the page address. The account ID is part of it. Copy it into the environment file.

### Which permissions does the access token need?

In the Graph API Explorer, add ads management and ads read. The app itself needs the use case to create and manage ads with the Marketing API.

### What if the first test fails?

Expect it. The first test showed an out of date call, and Claude debugged it by reading the error and updating its code. Ask it to retest, and let it fix its own mistakes before you step in.

### Is this safe to run on a live ad account?

Be careful. The build was a simple proof of concept that runs in a terminal. Do not publish an app and connect accounts carelessly, keep your keys private, and have the code checked before you rely on it.

Tools used: Claude Code, Antigravity, Anthropic API, Meta Ads Manager, Meta Marketing API, Python

Free templates for this guide: https://fluxomate.com/resources.html?r=build-a-media-buyer
