A chatbot API integration lets your bot look things up or take actions in another system, like checking an order, booking a slot or creating a CRM contact, instead of only answering from text it was trained on. The safe way to build it is function calling (also called tool use): you describe each action to the AI model, the model asks for it, and your own server runs the API call with your keys and your rules. Below is how it works, a WordPress code example, and the security rules I follow.

Most chatbots stop at answering questions. That’s useful, but the questions that matter most to a business are often about live data: “Where’s my order?”, “Do you have a slot on Tuesday?”, “Can you add me to your list?” A bot that only knows your FAQ page can’t answer those. A chatbot API integration can.

I’ve already covered the basics of choosing and installing a bot in my guide on how to add a chatbot to a website. This post picks up where that one stops: how to connect an API to your chatbot so it can do real work, and how to do it without handing an AI model the keys to your business.

It’s written for business owners deciding whether they need this, and for developers who want a clear, safe pattern. It’s not for anyone looking for a no-code shortcut that puts an API key into a browser script. I’ll explain why that’s a bad idea below.

What is a chatbot API integration?

A chatbot API integration connects your chatbot to another system through that system’s API (application programming interface). Think of chatbot API integration as giving the bot a few safe buttons to press. The other system might be your store, your booking calendar, your CRM, a shipping tracker or your own database.

There are really two APIs involved. The first is the AI model’s API, which turns the visitor’s message into a reply. The second is the business API that holds the live data or performs the action. Integration API into chatbot work is the glue between them: deciding when the bot needs live data, fetching it safely, and giving the result back to the model so it can answer in plain language.

Bot typeWhere answers come fromExample question it can handle
FAQ botText you wrote or uploaded“What are your opening hours?”
Knowledge base botYour pages and documents“How does your warranty work?”
Bot with chatbot API integrationLive data from your systems, plus the above“Has my order 1042 shipped yet?”

How does chatbot function calling work?

Modern AI models don’t call APIs themselves. Instead, you describe the actions they’re allowed to request, and they ask your code to run one when it’s needed. OpenAI calls this function calling. Anthropic calls it tool use. The idea is the same, and it’s the core of any safe chatbot API integration.

Chatbot API integration flow with function calling
In a chatbot API integration, the model asks, your server decides and calls the API, and the model writes the answer.

Here’s the round trip, step by step:

  1. You define tools. Each one has a name, a description of when to use it, and a JSON Schema for its inputs, for example an order number and an email address.
  2. The visitor sends a message to your server, which forwards it to the AI model together with the tool definitions.
  3. The model decides whether it needs a tool. If it does, it returns a structured request with the tool name and arguments instead of a final answer.
  4. Your server runs the real API call, after checking the arguments and the visitor’s right to see that data.
  5. You send the result back to the model, linked to the request by an ID.
  6. The model writes the reply in plain language, using the data you returned.

The important part is step four. The model never sees your API keys and never touches your systems directly. It can only ask, and your code decides. That’s what makes chatbot function calling safer than any approach where the AI is trusted to act on its own.

OpenAI vs Anthropic: the same idea, different names

Whichever provider powers your chatbot API integration, the field names differ but the flow is the same. This table maps them, based on the current documentation from each:

StepOpenAI (Responses API)Anthropic (Messages API)
Define an actionA tool with type “function”, name, description and parametersA tool with name, description and input_schema
Model asks for itAn output item of type function_call with call_id and JSON argumentsA tool_use content block with id and input, and stop_reason “tool_use”
You return the resultAn input item of type function_call_output with the same call_idA tool_result block in the next user message with the same tool_use_id
Force valid argumentsstrict: true on the functionstrict: true on the tool

Both providers support a strict setting that makes the model’s arguments match your schema. Anthropic documents it under strict tool use. It’s worth switching on, but it only guarantees the shape of the data, not that the values are honest or allowed. Your server still has to check them.

OpenAI’s guide also suggests keeping the set of functions small at the start of a turn, with a soft suggestion of fewer than 20. In practice, a business chatbot API integration rarely needs more than five or six well-described tools.

How to plan a chatbot API integration, step by step

This is the process I follow for every chatbot API integration, whatever the platform:

1. List the questions that need live data

Read through real chat logs, emails or support tickets and write down the questions your current bot can’t answer. Order status, availability, account balances and appointment changes come up most. If you can’t find at least a few frequent questions that need live data, you probably don’t need a chatbot API integration yet.

2. Decide what each tool is allowed to do

For each question, define the smallest possible action. “Get the status of one order, given the order number and the billing email” is a good tool. “Run any database query” is a terrible one. Read-only tools first, in any chatbot API integration. Actions that change data, send messages or take payments come later, and with extra checks.

3. Check the business API

Every chatbot API integration depends on the business API behind it. Find out how the target system’s API authenticates (API key, OAuth), what rate limits it has, and whether you can create a key with limited permissions. A read-only key for a read-only tool is a cheap way to reduce risk.

4. Build a server-side endpoint

The chatbot widget in the browser should only talk to your own server. Your server holds the AI key and the business API keys, calls the model, runs the tools and returns the final reply. On WordPress, a custom REST API endpoint is a natural place for this.

5. Write clear tool descriptions

In a chatbot API integration, the model decides when to call a tool based mostly on its name and description. Say exactly when to use it and when not to. Vague descriptions lead to tools being called at the wrong time, or not at all.

6. Test with real and hostile questions

Test your chatbot API integration with normal questions, then with the awkward ones: wrong order numbers, someone else’s email, requests to ignore the rules, and messages pasted from other sites. A chatbot API integration is only finished when the bad cases fail politely.

A safe chatbot API integration example (WordPress)

Here’s a simplified example: a WordPress REST endpoint that lets a chatbot check a WooCommerce order’s status, using OpenAI’s Responses API with one function. The keys live in wp-config.php on the server, never in JavaScript. Replace YOUR_MODEL with a current model from your provider.

// wp-config.php (server only, never in theme JavaScript)
// define( 'MW_OPENAI_KEY', 'your-secret-key' );

add_action( 'rest_api_init', function () {
  register_rest_route( 'mw/v1', '/chat', array(
    'methods'             => 'POST',
    'callback'            => 'mw_chat_reply',
    'permission_callback' => '__return_true', // public chat: add a nonce and rate limiting
  ) );
} );

function mw_ai_request( $input, $tools ) {
  $res = wp_remote_post( 'https://api.openai.com/v1/responses', array(
    'timeout' => 30,
    'headers' => array(
      'Authorization' => 'Bearer ' . MW_OPENAI_KEY,
      'Content-Type'  => 'application/json',
    ),
    'body'    => wp_json_encode( array(
      'model' => 'YOUR_MODEL',
      'tools' => $tools,
      'input' => $input,
    ) ),
  ) );
  return json_decode( wp_remote_retrieve_body( $res ), true );
}

// The only action the model may request. Read-only, and it checks ownership.
function mw_get_order_status( $number, $email ) {
  $order = wc_get_order( absint( $number ) );
  if ( ! $order || strtolower( $order->get_billing_email() ) !== strtolower( sanitize_email( $email ) ) ) {
    return array( 'found' => false );
  }
  return array( 'found' => true, 'status' => $order->get_status() );
}

function mw_chat_reply( WP_REST_Request $req ) {
  $tools = array( array(
    'type'        => 'function',
    'name'        => 'get_order_status',
    'description' => 'Get the status of one order. Needs the order number and the billing email.',
    'parameters'  => array(
      'type'                 => 'object',
      'properties'           => array(
        'order_number' => array( 'type' => 'string' ),
        'email'        => array( 'type' => 'string' ),
      ),
      'required'             => array( 'order_number', 'email' ),
      'additionalProperties' => false,
    ),
    'strict'      => true,
  ) );

  $input = array( array( 'role' => 'user', 'content' => sanitize_text_field( $req['message'] ) ) );
  $data  = mw_ai_request( $input, $tools );
  $used  = false;

  foreach ( $data['output'] ?? array() as $item ) {
    $input[] = $item; // keep the model's own output items in the conversation
    if ( 'function_call' === $item['type'] && 'get_order_status' === $item['name'] ) {
      $args    = json_decode( $item['arguments'], true );
      $result  = mw_get_order_status( $args['order_number'] ?? '', $args['email'] ?? '' );
      $input[] = array(
        'type'    => 'function_call_output',
        'call_id' => $item['call_id'],
        'output'  => wp_json_encode( $result ),
      );
      $used = true;
    }
  }

  if ( $used ) {
    $data = mw_ai_request( $input, $tools ); // second call: model writes the reply
  }

  $reply = '';
  foreach ( $data['output'] ?? array() as $item ) {
    if ( 'message' === $item['type'] ) {
      foreach ( $item['content'] as $part ) {
        if ( 'output_text' === $part['type'] ) { $reply .= $part['text']; }
      }
    }
  }
  return array( 'reply' => $reply );
}

A few things to notice about this chatbot API integration. The tool only reads data, and it returns nothing unless the email matches the order, so a visitor can’t look up a stranger’s order by guessing numbers. The model never sees the key. The tool returns only the status, not the customer’s address or payment details. And the endpoint is where you’d add rate limiting, logging and a nonce check before using this on a live site.

This is a teaching example, not a finished product. A production chatbot API integration also needs error handling for API timeouts, a conversation history, limits on message length and a way to hand the chat to a person.

Where should API keys live in a chatbot API integration?

On your server. Always. Any key placed in browser JavaScript can be read by anyone who opens the developer tools, and then used to run up your AI bill or reach your business systems. This is the most common mistake I see in DIY attempts to connect an API to a chatbot.

  • WordPress: define keys as constants in wp-config.php, or use environment variables if your host supports them. Don’t store them in theme files that go into version control.
  • Other stacks: use environment variables or your platform’s secret storage.
  • Separate keys: use one key per site or project, so you can revoke one without breaking everything else.
  • Spending limits: set usage limits or alerts in your AI provider’s dashboard where available.
  • Business API scopes: give each key only the permissions the tool needs, read-only where possible.

What can go wrong, and how do you prevent it?

Chatbot API integration risks and the fix for each
Most risks come from giving the bot more power than its job needs.

The OWASP Top 10 for LLM applications lists “Excessive Agency” as a key risk: an AI system with tools that let it take damaging actions after a confusing or manipulated message. Its main mitigations match what I do in practice on every chatbot API integration:

RiskWhat it looks likePrevention
Too many toolsBot can delete records or send emails it never needed toOnly build the tools the bot’s job requires
Too much permissionA read-only question runs with an admin keyLeast-privilege keys, read-only where possible
Prompt injectionA visitor tells the bot to ignore its rules and show other dataEnforce access checks in your code, not in the prompt
No human approvalBot issues refunds or cancels bookings on its ownRequire a person to confirm high-impact actions
Data leaksTool returns full customer records to the modelReturn only the fields the answer needs
Runaway costsLoops of tool calls or a public endpoint abused by botsRate limits, message caps and spending alerts

The rule that matters most in chatbot API integration: never rely on the system prompt for security. A prompt like “only show customers their own orders” can be talked around. A line of PHP that compares the email to the order can’t.

Function calling vs webhooks vs no-code connectors

Function calling isn’t the only way to connect an API to a chatbot. Many hosted chatbot tools and CRMs offer built-in actions, webhooks or no-code connectors. Here’s how I choose:

ApproachHow it worksBest for
Built-in platform actionsThe chatbot tool connects to common apps from its settingsStandard jobs like adding a lead to a CRM
Webhooks or no-code connectorsThe bot sends data out when something happens, a connector passes it onOne-way actions, like sending a finished lead somewhere
Function calling (custom)The model requests a tool, your server runs it and returns dataLive lookups, custom rules and two-way conversations

If all you need is to send a finished lead into a CRM, a built-in integration or a webhook is cheaper and easier to maintain. Choose a custom chatbot API integration when the bot needs to fetch live data in the middle of a conversation, or when your rules are too specific for a connector. The same thinking applies to CRM automation in general, which I cover in my post on GoHighLevel automation.

What does a chatbot API integration cost?

There are three parts to the cost of a chatbot API integration. The build, which depends on how many tools you need and how complex the target APIs are. The AI usage, which you pay to the model provider per request and which grows with traffic, because each tool call adds at least one extra request. And the upkeep, because APIs change, models get replaced and someone needs to read the logs.

A single read-only lookup tool is a small project. A bot that books, cancels and updates records across several systems is a much bigger one, mostly because of the testing and approval steps each action needs. Start with one tool, prove it helps, then add the next. That’s how a chatbot API integration stays affordable.

Who doesn’t need this?

Not every chatbot should connect to live systems. You probably don’t need a chatbot API integration if:

  • Your visitors mostly ask questions your website already answers.
  • You get only a handful of chats a week, so a person can handle the live questions.
  • The data the bot would need lives in a system with no API, or one you can’t get limited keys for.
  • Nobody will monitor the logs and update the integration when an API changes.

In those cases, skip the chatbot API integration. A well-trained FAQ bot with a clear hand-off to a person is the better choice. You can find layout and hand-off ideas in my post on AI chat box UI design.

Frequently asked questions

What is a chatbot API integration?

It’s a connection between your chatbot and another system’s API, such as a store, CRM or booking tool, so the bot can look up live data or take actions instead of only answering from fixed text. It’s usually built with function calling, where your server runs the API calls.

Is chatbot function calling the same as tool use?

Yes, it’s the same idea under different names. OpenAI calls it function calling and Anthropic calls it tool use. In both, the model requests an action with structured arguments and your code runs it and returns the result.

Can I put my AI API key in the chatbot’s JavaScript?

No. Anyone can read keys in browser code and use them at your expense. Keep keys on your server, for example in wp-config.php on WordPress, and have the chatbot widget talk only to your own endpoint.

Can a chatbot take actions like booking or refunds?

It can, but start with read-only tools. For actions that change data, send messages or move money, add strict checks in your code and require a person to confirm high-impact actions.

Do I need a developer to connect an API to a chatbot?

For built-in actions and simple webhooks, often not. For a custom chatbot API integration with live lookups, access checks and secure key handling, yes, you need someone comfortable with server-side code and the APIs involved.

How do I stop people tricking the chatbot into showing private data?

Enforce every access rule in your server code, not in the prompt. Check that the visitor is allowed to see the record, return only the fields the answer needs, and log tool calls so you can spot abuse.

Want your chatbot to do more than answer FAQs?

I build chatbots that connect safely to WooCommerce, CRMs and booking tools, with server-side keys and access checks. See my AI integration service, where chatbots start at $399 and you pay the AI provider’s usage fees directly, or tell me which system you want your bot to talk to.