# Integrating External APIs with Agentic AI: A Practical Approach

> Source: <https://dev.to/mzunain/integrating-external-apis-with-agentic-ai-a-practical-approach-3i43>
> Published: 2026-07-23 06:00:00+00:00

An agent without APIs is limited. Connected to APIs, it's unstoppable.

``` php
import requests

def get_weather(city: str) -> str:
    """Get current weather for a city"""
    response = requests.get(
        f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}"
    )
    data = response.json()
    return f"{data['main']['temp']}°C in {city}"

from langchain.tools import tool

@tooldef weather_tool(city: str) -> str:
    """Get weather for a city"""
    return get_weather(city)
python
def safe_api_call(func, *args, **kwargs):
    try:
        return func(*args, **kwargs)
    except TimeoutError:
        return "API timeout - try again"
    except requests.exceptions.ConnectionError:
        return "Connection failed - check internet"
    except Exception as e:
        return f"Error: {str(e)}"
python
from functools import wraps
import time

def rate_limit(calls_per_second: float):
    min_interval = 1.0 / calls_per_second
    last_called = [0.0]

    def decorator(func):
        @wraps(func)        def wrapper(*args, **kwargs):
            elapsed = time.time() - last_called[0]
            if elapsed < min_interval:
                time.sleep(min_interval - elapsed)
            result = func(*args, **kwargs)
            last_called[0] = time.time()
            return result
        return wrapper
    return decorator
```

Connecting to Slack:

``` python
from slack_sdk import WebClient

client = WebClient(token=SLACK_TOKEN)

@tooldef send_slack_message(channel: str, text: str) -> str:
    """Send message to Slack channel"""
    response = client.chat_postMessage(
        channel=channel,
        text=text
    )
    return f"Message sent to {channel}"
```

✅ Secure API keys in environment variables

✅ Implement timeout handling

✅ Log all API calls

✅ Cache responses when possible

✅ Test with mock APIs first

✅ Monitor API usage & costs

✅ Handle rate limiting gracefully

Agents that integrate 10+ APIs will be standard in 2026.

**What APIs are you connecting to your agents?**
