> For the complete documentation index, see [llms.txt](https://docs.opaquepay.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opaquepay.xyz/integrations/agentkit.md).

# Coinbase AgentKit

OpaquePay works with AgentKit through a custom `ActionProvider` that calls the OpaquePay HTTP API. Implement the provider below and pass it to `AgentKit`.

## Setup

```typescript
import { AgentKit, ActionProvider, Action } from "@coinbase/agentkit";
import { ChatOpenAI } from "@langchain/openai";

class OpaquePayActionProvider extends ActionProvider {
  private apiKey: string;

  constructor({ apiKey }: { apiKey: string }) {
    super();
    this.apiKey = apiKey;
  }

  getActions(): Action[] {
    return [
      {
        name: "opaquepay_send_payment",
        description: "Send USDC to a recipient via OpaquePay.",
        schema: {
          type: "object",
          properties: {
            to: { type: "string", description: "@handle or Solana address" },
            amount: { type: "string", description: "Decimal amount e.g. '5.00'" },
            memo: { type: "string" },
            confidential: { type: "boolean", default: true },
          },
          required: ["to", "amount"],
        },
        invoke: async ({ to, amount, memo, confidential = true }) => {
          const res = await fetch("https://api.opaquepay.xyz/v1/transfers", {
            method: "POST",
            headers: {
              Authorization: `Bearer ${this.apiKey}`,
              "Content-Type": "application/json",
            },
            body: JSON.stringify({ to, amount, currency: "USDC", memo, confidential }),
          });
          return res.json();
        },
      },
      {
        name: "opaquepay_get_balance",
        description: "Get the agent's current USDC balance.",
        schema: { type: "object", properties: {} },
        invoke: async () => {
          const res = await fetch("https://api.opaquepay.xyz/v1/account", {
            headers: { Authorization: `Bearer ${this.apiKey}` },
          });
          const data = await res.json();
          return { balance: data.balance, currency: data.currency };
        },
      },
      {
        name: "opaquepay_list_transactions",
        description: "Get recent transaction history.",
        schema: {
          type: "object",
          properties: {
            limit: { type: "number", default: 10 },
          },
        },
        invoke: async ({ limit = 10 }) => {
          const res = await fetch(
            `https://api.opaquepay.xyz/v1/transfers?limit=${limit}`,
            { headers: { Authorization: `Bearer ${this.apiKey}` } },
          );
          return res.json();
        },
      },
    ];
  }
}

const agentKit = new AgentKit({
  actionProviders: [
    new OpaquePayActionProvider({
      apiKey: process.env.AGENT_API_KEY,
    }),
  ],
});
```

## Available actions

### `opaquepay_send_payment`

Send USDC to a recipient.

```typescript
// Action schema — the LLM populates these fields
{
  to: string;         // "@handle" or Solana address
  amount: string;     // decimal string e.g. "5.00"
  memo?: string;
  confidential?: boolean;  // default: true
}
```

### `opaquepay_get_balance`

Get the agent's current USDC balance.

### `opaquepay_list_transactions`

Get recent transaction history.

### `opaquepay_create_request`

Create a payment request URL for a specific amount. Call `POST /v1/transfers/requests` with `amount`, `currency`, and optional `memo`.

## Full example

```typescript
import { AgentKit, createReActAgent } from "@coinbase/agentkit";
import { ChatOpenAI } from "@langchain/openai";

const agentKit = new AgentKit({
  actionProviders: [
    new OpaquePayActionProvider({
      apiKey: process.env.AGENT_API_KEY,
    }),
  ],
});

const llm = new ChatOpenAI({ model: "gpt-4o" });

const agent = createReActAgent(llm, agentKit.getActions());

const response = await agent.invoke({
  messages: [
    {
      role: "user",
      content: "Check my balance and then pay @perplexity 0.05 USDC for a search",
    },
  ],
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.opaquepay.xyz/integrations/agentkit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
