# Build a Gmail agent with Claude Code

> Have Claude Code build a Gmail agent with the Agent200 SDK: managed OAuth, ready-made tools and one API key.

- Page: https://www.agent200.com/tools/gmail/framework/claude-code/
- Connector: [Gmail](https://www.agent200.com/tools/gmail.md)
- Framework: Claude Code
- Updated: 2026-11-15

## Instructions for AI agents

Goal: connect Gmail to Claude Code with Agent200.
Guide: https://www.agent200.com/tools/gmail/framework/claude-code/

1. Get an Agent200 API key. If the developer has none, send them to https://agent200.com/platform/apikeys/ and ask them to choose "Create an API key". Read the key from the AGENT200_API_KEY environment variable. Never ask for it in chat, and never write it into code, prompts or logs.
2. Make sure Gmail is enabled for the project in the Agent200 dashboard (Connectors), with the endpoints and scopes the task needs.
3. Add the Agent200 SDK to the project and create a client with that key.
4. Give every request a stable id for the end user. Agent200 uses only that user's own connections.
5. Connect the user's Gmail account through Agent200. If Agent200 returns an authorization link, show it to the user and continue once they have approved access on Gmail.
6. Run requests through Agent200 with a model (for example openai/gpt-5.6-sol) and "gmail" in the tools. The model decides when a Gmail tool is needed; Agent200 executes the call.
7. Check it works with this request: "What did the finance team send me this week?"
   What should come back:
   - An answer in `result.output`, built from the user's own Gmail data.
   - Behind the scenes, the model calls a Gmail tool, such as `gmail_search`, and Agent200 runs it.
8. If a tool is missing or a call is refused, check the project's Connectors settings in the dashboard and the access the user granted in Gmail, then retry.

The code on the guide page is a conceptual example of the SDK. SDK reference: https://docs.igpt.ai/

## Overview

This guide has Claude Code build a Gmail agent with the Agent200 SDK, in your own project. When you finish, your agent can call the Gmail tools for each of your users.

Claude Code writes the code from the steps below; Agent200 runs the Gmail calls with each user's own connection and handles the OAuth flow and the tokens. You do not build or maintain a Gmail integration.

- **Connector:** [Gmail](https://www.agent200.com/tools/gmail/)
- **Works with:** Claude Code · Coding agent, with the SDK
- **Authentication:** Managed OAuth, per end user
- **You need:** [An Agent200 API key](https://agent200.com/platform/apikeys/)
- **Tools:** [7 tools](https://www.agent200.com/tools/gmail/framework/claude-code/#tools)
- **Model in examples:** `openai/gpt-5.6-sol`

## Before you start

- **An Agent200 API key.** Create one on the [API keys page](https://agent200.com/platform/apikeys/) of the dashboard.
- **Gmail enabled for your project.** In the dashboard's Connectors settings, with the endpoints and scopes your agent needs.
- **An end user with a Gmail account.** They approve access once, on Gmail's own page.
- **Claude Code in your project.** It writes the code with the Agent200 SDK; you review it.

## Connect Gmail to Claude Code

### Step 1: Create your Agent200 API key

Open the API keys page in the Agent200 dashboard and choose Create an API key. Copy the key and store it as an environment variable, AGENT200_API_KEY, or in your secrets manager. One key covers Gmail and every other connector and model enabled for your project. Keep it out of chats, prompts and source control.

Create an API key: https://agent200.com/platform/apikeys/

File `.env`:

```bash
# Keep the key out of your code, prompts and chats.
export AGENT200_API_KEY="paste-your-key-here"
```

(Conceptual example of the Agent200 SDK.)

### Step 2: Give this guide to Claude Code

Start Claude Code in your project and paste the agent brief from this page, or give it the address of this guide's Markdown version. Claude Code follows the steps below in order: the SDK, the Gmail connection and the first request. Review the code it writes before you run it.

### Step 3: Set up the Agent200 SDK

Add the SDK to your project and create a client with the key from the environment.

File `agent.js`:

```js
// One Agent200 API key covers every connector enabled for the project.
const agent200 = new Agent200({
  apiKey: process.env.AGENT200_API_KEY,
});
```

(Conceptual example of the Agent200 SDK.)

### Step 4: Let your user connect Gmail

Each end user authorizes their own Gmail account once, through managed OAuth. If the user has not connected yet, Agent200 returns an authorization link: show it to them, and they approve access on Gmail's own page. Agent200 handles the callback, stores the tokens and refreshes them.

File `connect.js`:

```js
// Each end user authorizes their own Gmail account, once.
const connection = await agent200
  .user("user_123")
  .connect("gmail");

if (connection.authorizationUrl) {
  // Show this link to your user; Agent200 handles the rest.
  console.log(connection.authorizationUrl);
}
```

(Conceptual example of the Agent200 SDK.)

### Step 5: Run with the Gmail tools

Name the user, the model and Gmail in the tools. The model decides when a Gmail tool is needed, and Agent200 executes the call with the user's own connection.

File `run.js`:

```js
const result = await agent200
  .user("user_123")
  .run({
    model: "openai/gpt-5.6-sol",
    input: "What did the finance team send me this week?",
    tools: ["gmail"],
  });

console.log(result.output);
```

(Conceptual example of the Agent200 SDK.)

## Test your connection

Ask: "What did the finance team send me this week?"

What should come back:

- An answer in `result.output`, built from the user's own Gmail data.
- Behind the scenes, the model calls a Gmail tool, such as `gmail_search`, and Agent200 runs it.

If Agent200 returns an authorization link instead, the user has not connected Gmail yet. Go back to the connect step.

## Gmail tools Claude Code can call

- **Search email** (`gmail_search`, read): Find messages with Gmail's search syntax.
- **Get a message** (`gmail_get_message`, read): Read a message with its headers and body.
- **Get a thread** (`gmail_get_thread`, read): Read every message in a conversation.
- **Send email** (`gmail_send`, write): Send a new message or a reply.
- **Create a draft** (`gmail_create_draft`, write): Save a message as a draft for the user to review.
- **Add a label** (`gmail_modify_labels`, write): Add or remove labels on a message.
- **List labels** (`gmail_list_labels`, read): List the user's labels.

## How it works

1. **Your app sends the request.** It calls Agent200 with the model, instructions, the input, the end user's id and the Gmail tools.
2. **The model picks a tool.** The model decides whether a Gmail tool is needed, and with which arguments.
3. **Agent200 runs the call.** It uses that user's own Gmail connection, within the endpoints and scopes your project allows, and returns the result to the model.
4. **Your app gets the result.** Agent200 returns the completed result. Your app decides when the agent runs and what happens next.

**Each user's own connection.** Connections belong to individual end users. A request for one user never reaches another user's Gmail account.

**Permissions at every level.** Your project settings decide what the agent may request, the end user decides what they authorize, and Gmail enforces what its API grants.

## Troubleshooting

### The request says Gmail authorization is required

The end user has not connected Gmail yet, or the connection needs to be approved again. Agent200 returns an authorization link: show it to the user, let them approve access on Gmail's own page, then run the request again.

### Claude Code does not use the Gmail tools

Check that Gmail is enabled for your project in the dashboard's Connectors settings and that it is in the tools you send with the request. Naming Gmail in the request, or in the instructions, also helps the model choose the right tool.

### A tool call is refused or returns less than expected

Agent200 runs only what your project allows (services, endpoints and scopes), and Gmail returns only what the end user authorized. Widen the endpoints or scopes in the dashboard if the agent needs more, then ask the user to connect Gmail again so they can approve the new access.

### The results come from the wrong account

Every request names an end user (`user_123` in the examples). Pass the id of the person your agent is working for: Agent200 then uses only that user's Gmail connection, never another user's.

### The API key was pasted into a chat or committed

Create a new key on the [API keys page](https://agent200.com/platform/apikeys/), update `AGENT200_API_KEY` wherever your app reads it, and stop using the old one. Keep keys in environment variables or a secrets manager, never in prompts, chats or source control.

## Use Gmail with another framework

- [Gmail + Claude](https://www.agent200.com/tools/gmail/framework/claude.md)
- [Gmail + ChatGPT](https://www.agent200.com/tools/gmail/framework/chatgpt.md)
- [Gmail + Muse](https://www.agent200.com/tools/gmail/framework/muse.md)
- [Gmail + Grok Bot](https://www.agent200.com/tools/gmail/framework/grok-bot.md)
- [Gmail + OpenAI Dots](https://www.agent200.com/tools/gmail/framework/openai-dots.md)
- [Gmail + Claude Duet](https://www.agent200.com/tools/gmail/framework/claude-duet.md)
- [Gmail + Hermes Agent](https://www.agent200.com/tools/gmail/framework/hermes-agent.md)
- [Gmail + OpenClaw](https://www.agent200.com/tools/gmail/framework/openclaw.md)

---

Agent200: https://www.agent200.com/ · API keys: https://agent200.com/platform/apikeys/ · Docs: https://docs.igpt.ai/
