Skip to main content
This guide explains how to connect an AI agent (Claude, GPT, LangChain, CrewAI, etc.) to the Leonar API so it can manage contacts, enroll in sequences, and track deals on behalf of your users.

How it works

The Leonar API is a standard REST API with an OpenAPI 3.0 spec. AI agent frameworks consume this spec to generate tool definitions automatically.
The OpenAPI spec at openapi.yaml is the single source of truth for REST-based agents. If your client supports MCP, you can also connect directly to Leonar’s native MCP server.

Setup

1. Create a scoped API key

Go to Settings > API and create a key with only the scopes your agent needs.
Never give an agent admin scope. Always use the minimum scopes required.

2. Load the OpenAPI spec

3. Set the base URL and auth header

Rate limiting strategy

The API allows 2000 requests per hour. For autonomous agents:
  • Check headers: Every response includes X-RateLimit-Remaining and X-RateLimit-Reset
  • Batch operations: Use bulk endpoints (e.g., enroll up to 500 contacts at once) instead of individual calls
  • Exponential backoff: On 429 responses, wait 2^attempt seconds before retrying
  • Pagination: Default limit=50. Use offset to paginate. Don’t fetch all pages unless needed.

Common agent workflows

Workflow 1: Enrich and enroll in sequence

Workflow 2: Deal pipeline management

Error handling for agents

Your agent should handle these error patterns:

Best practices for autonomous agents

Start with read-only

Let the agent explore data before writing. Most mistakes come from creating or updating with wrong data.

Confirm before bulk actions

Enrolling 500 contacts in a sequence is hard to undo. Have the agent confirm with the user before bulk writes.

Check existing data first

Before creating a contact, search by email or profile URL to avoid duplicates.

Testing your agent

  1. Create a test API key with read_only scopes only
  2. Run your agent on a read-only task (e.g., “list all active projects and their candidate counts”)
  3. Verify outputs — check that the agent correctly interprets the API responses
  4. Upgrade scopes once read-only works, add write scopes one at a time
  5. Test write operations on a test project before going live