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 search candidates, 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: Source and add candidates to a project

location_ids requires LinkedIn geo IDs, not plain-text names. You must call GET /sourcing/linkedin/locations?q=Paris&account_id=ACCOUNT_ID first to resolve a location name to its LinkedIn numeric ID. Passing plain text like {"Paris": "Paris"} will silently return zero results.
LinkedIn search pagination is cursor-based. After POST /sourcing/linkedin/search, store data.cursor and send it on the next request. Do not request page 2 by sending only page: 2; it can return the same profiles as page 1.
LinkedIn Classic search may return null first_name and last_name. Set resolve_names: true and provide account_id in the add-to-project request to automatically resolve missing names via LinkedIn profile lookup. Without this, contacts are created with “Unknown” as their first name.

Workflow 2: Enrich and enroll in sequence

Workflow 3: 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.

Use source-specific endpoints

Use /sourcing/linkedin/search instead of the generic /sourcing/search. The flat schemas are easier for agents to construct.

Check existing data first

Before creating a contact, search by email or LinkedIn 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