A Claude agent can reason about almost anything. It cannot tell you where an IP address sits, how a stock closed today, whether a flight is in the air, what Google returns for a query, or what the news said an hour ago. That data lives behind APIs, and the model needs a way in.
This post wires five live-data APIs into a Claude agent through a single key: IPstack for geolocation, Marketstack for stock prices, Aviationstack for flights, SERPstack for search, and Mediastack for news. Every code block runs, and every response is the real shape the endpoint returns.
The five APIs are part of the APILayer suite: one account, one API key, one dashboard, one invoice.
Table of Contents
How do I connect an API to Claude tool use?
You describe the API to Claude as a tool, Claude decides when to call it, and your code runs the request. Claude tool use with APIs is a four-step loop: define the tool with a JSON schema, send the user message, receive a tool_use block, and return the result as a tool_result.
Start with a tool definition. The input_schema tells Claude exactly what arguments to produce.
ip_lookup_tool = {
"name": "get_ip_location",
"description": "Look up the geographic location of an IPv4 or IPv6 address.",
"input_schema": {
"type": "object",
"properties": {
"ip": {
"type": "string",
"description": "The IP address to locate, e.g. 134.201.250.155."
}
},
"required": ["ip"]
}
}
Send it with the Messages API. The tools list is all Claude needs.
import json, anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY
response = client.messages.create(
model="claude-opus-4-8", # swap in a smaller model for high-volume calls
max_tokens=1024,
tools=[ip_lookup_tool],
messages=[
{"role": "user", "content": "Where is IP 134.201.250.155?"}
],
)
When Claude wants live data, it stops with stop_reason: “tool_use” and returns a tool call instead of a text answer.
# response.stop_reason == "tool_use"
# response.content includes:
# {
# "type": "tool_use",
# "id": "toolu_01A09q90qw90lq917835lq9",
# "name": "get_ip_location",
# "input": {"ip": "134.201.250.155"}
# }
Run the API call and hand the JSON back in a tool_result. One small helper keeps every request on the same key.
import os, requests
KEY = os.environ["APILAYER_KEY"]
def call(host, path, **params):
params["access_key"] = KEY
return requests.get(f"http://api.{host}.com{path}", params=params).json()
tool_use = next(b for b in response.content if b.type == "tool_use")
result = call("ipstack", f"/{tool_use.input['ip']}")
followup = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
tools=[ip_lookup_tool],
messages=[
{"role": "user", "content": "Where is IP 134.201.250.155?"},
{"role": "assistant", "content": response.content},
{"role": "user", "content": [
{"type": "tool_result", "tool_use_id": tool_use.id, "content": json.dumps(result)}
]},
],
)
Claude reads the result and answers. Every endpoint below uses the same loop.
Five live-data tools, one API key
IPstack, Marketstack, Aviationstack, SERPstack, and Mediastack authenticate with the same access_key. One APILayer key covers every call below.
IPstack: where is this IP?
IPstack maps an IP address to a country, region, city, and coordinates.
curl "http://api.ipstack.com/134.201.250.155?access_key=YOUR_APILAYER_KEY"
{
"ip": "134.201.250.155",
"type": "ipv4",
"country_code": "US",
"country_name": "United States",
"region_name": "California",
"city": "Los Angeles",
"latitude": 34.0655,
"longitude": -118.2405
}
Reference: IPstack documentation.
Marketstack: how did this stock close?
Marketstack returns real-time, intraday, and end-of-day prices. The endpoint runs on v2, and each record carries the ticker name, exchange, and pricing currency.
curl "http://api.marketstack.com/v2/eod?access_key=YOUR_APILAYER_KEY&symbols=AAPL"
{
"pagination": { "limit": 100, "offset": 0, "count": 100, "total": 9944 },
"data": [
{
"open": 228.46,
"high": 229.52,
"low": 227.3,
"close": 227.79,
"volume": 34025967.0,
"name": "Apple Inc",
"exchange_code": "NASDAQ",
"asset_type": "Stock",
"price_currency": "usd",
"symbol": "AAPL",
"exchange": "XNAS",
"date": "2024-09-27T00:00:00+0000"
}
]
}
Reference: Marketstack documentation.
Aviationstack: is this flight in the air?
Aviationstack returns live flight status, aircraft, and position.
curl "http://api.aviationstack.com/v1/flights?access_key=YOUR_APILAYER_KEY&flight_status=active&limit=1"
{
"pagination": { "limit": 1, "offset": 0, "count": 1, "total": 12043 },
"data": [
{
"flight_date": "2024-09-27",
"flight_status": "active",
"departure": { "airport": "San Francisco International", "iata": "SFO" },
"arrival": { "airport": "Dallas/Fort Worth International", "iata": "DFW" },
"airline": { "name": "American Airlines", "iata": "AA" },
"flight": { "number": "1004", "iata": "AA1004" },
"live": { "latitude": 36.2856, "longitude": -106.807, "altitude": 8846.82 }
}
]
}
Reference: Aviationstack documentation.
SERPstack: what does Google return?
SERPstack runs a live Google search and returns the results page as structured JSON, including organic results, ads, and the knowledge graph.
curl "http://api.serpstack.com/search?access_key=YOUR_APILAYER_KEY&query=mcdonalds"
{
"request": { "success": true },
"search_parameters": {
"engine": "google",
"type": "web",
"device": "desktop",
"query": "mcdonalds"
},
"search_information": { "total_results": 1044000000 },
"organic_results": [
{
"position": 1,
"title": "McDonald's",
"url": "https://www.mcdonalds.com/us/en-us.html",
"domain": "www.mcdonalds.com",
"snippet": "Order McDelivery or find a nearby restaurant."
}
]
}
Reference: SERPstack documentation.
Mediastack: what is in the news?
Mediastack returns live and historical news articles from thousands of sources, with filters for language, country, category, and keyword.
curl "http://api.mediastack.com/v1/news?access_key=YOUR_APILAYER_KEY&languages=en&limit=1"
{
"pagination": { "limit": 1, "offset": 0, "count": 1, "total": 9350 },
"data": [
{
"author": "Newsroom Staff",
"title": "Markets close higher as tech shares rally",
"description": "Major indices ended the session up on a broad tech rally.",
"url": "https://example.com/markets-close-higher",
"source": "Example News",
"language": "en",
"country": "us",
"published_at": "2024-09-27T18:34:00+00:00"
}
]
}
Reference: Mediastack documentation.
Wiring all five into the agent
The same helper backs all five. Map each tool name to a call, changing host and path.
HANDLERS = {
"get_ip_location": lambda i: call("ipstack", f"/{i['ip']}"),
"get_stock_eod": lambda i: call("marketstack", "/v2/eod", symbols=i["symbols"]),
"get_flights": lambda i: call("aviationstack", "/v1/flights",
flight_status=i.get("status", "active"), limit=1),
"search_google": lambda i: call("serpstack", "/search", query=i["query"]),
"get_news": lambda i: call("mediastack", "/v1/news",
languages=i.get("language", "en"), limit=1),
}
Route each tool_use block to HANDLERS[block.name], return the JSON as a tool_result, and loop until Claude stops asking for tools. One key covers all five, so the agent runs on a single credential.
Create one APILayer account, grab your API key, and give your agent live data in minutes. No credit card required. Start here: https://apilayer.com/products/
FAQ
How do I connect an API to Claude tool use?
Define the API as a tool with a JSON input_schema, pass it in the tools list, and watch for a tool_use block in the response. Run the request, return the output as a tool_result, and Claude produces the final answer.
Can one API key power multiple AI agent tools?
Yes. One APILayer key authenticates every suite API. Above, one key drives geolocation, stock, flight, search, and news tools with no per-service setup.
Which APILayer APIs work as live-data tools for AI agents?
Any suite API that returns structured JSON. This post uses IPstack, Marketstack, Aviationstack, SERPstack, and Mediastack for location, market, flight, search, and news data.
Do I need a separate account for each APILayer API?
No. One APILayer account gives one key, one dashboard, and one invoice across the suite.
What live data can a Claude agent fetch with the APILayer suite?
Geolocation from IPstack, stock prices from Marketstack, flight status from Aviationstack, Google search results from SERPstack, and news headlines from Mediastack, all through the same key.