# brapi.dev GPT Action

Use this guide to connect a Custom GPT to the read-only brapi Brazilian financial data API.

## OpenAPI schema

Import this schema in the GPT Action editor:

- https://brapi.dev/swagger/gpt.json

The schema contains 28 common operations. It stays below ChatGPT's 30-operation limit.

## OAuth 2.0

Configure the action with these values:

- Authorization URL: https://brapi.dev/oauth/authorize
- Token URL: https://brapi.dev/oauth/token
- Scope: mcp:read
- Token exchange method: Default (POST request)
- Privacy policy: https://brapi.dev/legal/privacy-policy

The flow reuses brapi's MCP OAuth issuer and access-token validation. The GPT action sends the access token as `Authorization: Bearer TOKEN` to protected REST endpoints.

## Register the GPT client

Save the GPT once, then copy the Callback URL shown in the action Authentication panel.
Use the callback ID from that field, not the ID from another ChatGPT URL.
The callback ID can change after an action or GPT update.
Register both supported ChatGPT callback domains with that exact ID:

~~~bash
curl -X POST https://brapi.dev/oauth/register \
  -H 'Content-Type: application/json' \
  -d '{
    "redirect_uris": [
      "https://chatgpt.com/aip/GPT_ACTION_ID/oauth/callback",
      "https://chat.openai.com/aip/GPT_ACTION_ID/oauth/callback"
    ],
    "client_name": "brapi GPT",
    "grant_types": ["authorization_code", "refresh_token"],
    "response_types": ["code"],
    "token_endpoint_auth_method": "client_secret_post",
    "scope": "mcp:read"
  }'
~~~

Copy `client_id` and `client_secret` into the GPT Action OAuth settings. Keep the client secret private. The registration response returns it only once.
For a confidential client, brapi also accepts later ChatGPT callback IDs that match the standard `/aip/g-.../oauth/callback` path. This supports GPT action updates without a new client registration.

## Use the action

- Ask for a current quote with a B3 ticker, such as PETR4 or VALE3.
- Ask for historical prices, dividends, financial statements, FIIs, exchange rates, crypto, inflation, Selic, or Treasury indicators.
- Use symbols separated by commas for multiple assets.
- Use the sandbox tickers PETR4, VALE3, MGLU3, and ITUB4 before authenticated requests.
- Treat returned data as informational, not financial advice.

## Related resources

- https://brapi.dev/llms.txt
- https://brapi.dev/developers
- https://brapi.dev/openapi.json
- https://brapi.dev/docs/mcp
