0
Phase 6

External APIs

~3 min read

Concept & How It Works

    Why Does It Exist?

    Real-world agent tasks require live data from Stripe, Salesforce, GitHub, and hundreds of other services. API tools are the integration layer.

    Real-World Analogy

    External API tools are the agent's phone book and dialer — connecting to any business in the world that has an API.
    Loading diagram...

    Visual Workflows

    What is External APIs?

    Loading diagram...

    Example

    Scenario

    A sales agent calls the HubSpot API to create a contact, the Stripe API to check subscription status, and Slack to notify the account owner.

    Solution

    In Tool Calling & Function Calling, apply External APIs to this scenario: A sales agent calls the HubSpot API to create a contact, the Stripe API to check subscription status, and Slack to notify the account owner. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

    Practice Task

    Do this before moving to the next module — reading alone is not enough.

    Open the Code Walkthrough below and run it locally. Change one parameter related to External APIs (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

    Code Walkthrough

    Highlighted lines show where External APIs happens in the code.

    External APIs
    1def create_hubspot_contact_tool(api_key):  # define a reusable function2  def create_contact(email, name):  # define a reusable function3      resp = requests.post(4          "https://api.hubapi.com/crm/v3/objects/contacts",5          headers={"Authorization": f"Bearer {api_key}"},6          json={"properties": {"email": email, "firstname": name}},7      )8      resp.raise_for_status()9      return resp.json()  # return the result10  return {  # return the result11      "name": "create_hubspot_contact",12      "handler": create_contact,13      "schema": {...},14  }

    Commands to Remember

    Commands to Remember

    • client.chat.completions.create(..., tools=[...]) # pass tool schemas to API
    • json.loads(response.choices[0].message.tool_calls[0].function.arguments) # parse tool args
    • pip install pydantic # validate tool inputs with schemas

    Common Mistakes

    • Treating External APIs as a black box without evaluation
    • Ignoring cost and latency in production
    • Skipping error handling for external apis

    Cheat Sheet

    Quick recap — the most important points from this module.

    Cheat Sheet

    quick ref
    • External APIs
    • OAuth
    • Rate Limiting
    • OpenAPI