Why Connect Your AI Agent to Your App With an API
An AI agent API lets your own app talk to the agent you built, with its knowledge, rules and leads. What it is, when to use it, how it works, and why.

What is an AI agent API?
An AI agent API lets your own software send a message to an agent you already built and get its answer back. The agent keeps its instructions, knowledge, model, tools and safety rules. Your app only sends the question.
That is the difference with a raw model API. A model API gives you text generation and leaves the rest to you: prompts, document search, memory, rate limits, billing. IMFA's REST API gives you a managed agent that already has all of that, behind one agent-scoped key.
You build the agent with the AI chatbot builder. The API is one more place it can answer, next to your website, WhatsApp, Instagram, Facebook, Telegram, Discord and the voice line.
When should you connect your agent through an API?
Reach for the API when the conversation happens inside something you own:
- Your app or client portal needs a help assistant that knows your policies, without a second chatbot to maintain.
- Your backend should answer questions from another system, such as order pages, a booking tool or an internal dashboard.
- You want your leads in your CRM. The API returns the leads the agent captured on every channel, so you can sync them on a schedule.
- You need the conversation history for reporting or quality review.
If you only need a chat bubble on a website, the one-line embed is simpler. The API is for when your product, not the widget, is the interface.
How the IMFA agent API works
The base URL is https://site.imfa.app/v1. Every call needs the agent's key and must come from trusted server code, never a browser or a mobile bundle.
- Publish the agent. Set its instructions, knowledge, model and tools in IMFA, test real questions, and publish. The API serves the published version.
- Generate the key. Open the agent's API view or the API Keys screen and generate a key. It is shown once and stored only as a hash. Keep it in a server environment variable such as
IMFA_API_KEY. - Send a chat request.
POST /v1/agents/{slug}/chatwithAuthorization: Bearer <key>, a unique Idempotency-Key (8 to 128 characters) and a JSON body withmessageand an optionalsessionId. The reply comes back with asessionIdandusage.credits. - Continue the conversation. Leave out
sessionIdon the first turn, then send back the one you received. The agent remembers the context. - Read what happened.
GET /v1/agents/{slug}/sessionslists conversations,GET /v1/agents/{slug}/sessions/{sessionId}/messagesreads one, andGET /v1/agents/{slug}/leadsreturns captured leads. Lists return 20 items by default, up to 100, with a cursor.GET /v1/agentsconfirms which agent the key serves.
Limits are explicit: the first 4,000 characters of a message are used, bodies are capped at 64,000 bytes, and errors are typed (validation, authentication, credits, rate limit, server). A 429 comes with Retry-After; a 402 means the owner's credits are empty.
Why use the agent API instead of building your own
You skip months of plumbing. Document search, sessions, rate limits, retries, credit accounting and prompt-injection rules are already running. Your team writes one HTTP call.
One agent, one behavior. The answer your app shows is the same one your website and WhatsApp give, because it is the same agent. Update it once in IMFA and every surface follows.
Retries are safe. The idempotency key means a network retry returns the original reply instead of charging a second turn.
Leads stop living in silos. Pull every captured lead through one endpoint, whatever channel it came from.
You can still go fully custom. If you need to own every layer, a raw model API gives you that control, at the cost of building and running it yourself. Coding agents like Codex and Claude Code can also manage IMFA agents through MCP, while your server uses the REST key to serve customers.
Frequently asked questions about the AI agent API
Can I call the AI agent API directly from a browser?
No. The key spends the owner's credits and must stay on a trusted server. The API does not open broad browser access. Have your browser call your own protected endpoint, which then calls IMFA.
How do I authenticate an IMFA agent API request?
Generate an agent-scoped key in the agent's API view or the API Keys screen, then send Authorization: Bearer YOUR_API_KEY from server code. An MCP token is a different credential and does not work here.
How do I continue the same API conversation?
Leave out sessionId on the first chat request, save the sessionId the API returns, and send it with the next message. Session IDs from website or channel conversations are read-only and cannot continue an API conversation.
Why is an Idempotency-Key required for chat?
It makes retries safe. An exact retry with the same key returns the same result instead of creating a new turn. Use a fresh key for every new message.
Does the agent API use my knowledge and tools?
Yes. It calls the published agent with its instructions, model, knowledge, skills, tools and safety rules. Answers still depend on the published configuration, your credits and current service limits.
What happens when the API is rate limited or out of credits?
You get a 429 with a Retry-After header when rate limited, and a 402 when the owner's credits are empty. Handle every documented status code in your integration.

