---
title: "Dify.ai"
description: "Bring APIBrasil into Dify.ai through API Extensions and build AI agents with live access to Brazilian data."
lang: en
canonical: https://doc.apibrasil.io/mcp/chatbots/dify
markdown: https://doc.apibrasil.io/mcp/chatbots/dify.md
source: apibrasil-documentation
---

# Dify.ai

> Bring APIBrasil into Dify.ai through API Extensions and build AI agents with live access to Brazilian data.

- **Category:** Chatbots
- **Difficulty:** Medium
- **Protocol:** calls the REST gateway over HTTP
- **Updated on:** January 14, 2026

## Prerequisites

- A Dify.ai account (self-hosted or cloud)
- Basic OpenAPI/Swagger knowledge
- APIBrasil tokens

## Configuration

- **File:** `apibrasil-openapi.yaml`

```yaml
openapi: 3.0.0
info:
  title: APIBrasil
  version: 2.0.0
servers:
  - url: https://gateway.apibrasil.io/api/v2
security:
  - bearerAuth: []
  - deviceToken: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
    deviceToken:
      type: apiKey
      in: header
      name: DeviceToken
paths:
  /cep/cep:
    post:
      summary: Consultar CEP
      operationId: consultarCep
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                cep:
                  type: string
                  example: "01001000"
      responses:
        '200':
          description: Sucesso
          content:
            application/json:
              schema:
                type: object
```

## Step by step

1. **Write the OpenAPI schema** — Create a YAML or JSON file with the APIBrasil OpenAPI schema (see above)
2. **Import it into Dify** — In Dify Studio, go to Tools > API Extensions > Import OpenAPI
3. **Set up authentication** — Add your APIBrasil credentials in the authentication section
   ```text
   Bearer Token: seu_bearer_token
   Device Token: seu_device_token
   ```
4. **Test the tool** — Use Dify's Test Tool to confirm the connection to APIBrasil
5. **Add it to the agent** — In your Agent or Chatflow, add the APIBrasil tool to the list of available tools
6. **Set up the prompts** — Tell the agent when to reach for APIBrasil — for example: "when the user asks about a postcode, use the consultarCep tool"

## Troubleshooting

- **The OpenAPI import fails** — Check that the YAML is well formed. An online validator such as swagger.io/tools helps
- **Authentication keeps failing** — Make sure you are sending both the Bearer Token and the Device Token, in the right headers
- **The agent never uses the tool** — Be more explicit in the system prompts about when and how to use the APIBrasil tools
- **Requests time out** — Raise the timeout in Dify's advanced settings for APIs that can take longer

## Related links

- [Official Dify documentation](https://docs.dify.ai)
- [The APIBrasil OpenAPI spec](https://doc.apibrasil.io/mcp/exemplos/openapi.md)
- [Other chatbot platforms](https://doc.apibrasil.io/mcp/chatbots.md)
- [Flowise integration](https://doc.apibrasil.io/mcp/chatbots/flowise.md)

## See also

- MCP guide: [MCP guide](https://doc.apibrasil.io/mcp.md)
- Documentation index: https://doc.apibrasil.io/llms.txt
- HTML version of this page: https://doc.apibrasil.io/mcp/chatbots/dify
