Claude Code is great at writing and running code, but it doesn’t know today’s weather in Berlin. It doesn’t know the current EUR/USD rate. It can’t tell you what country owns a given IP address. None of that lives in its training data, and even if it did, it would be stale.
That gap is exactly what APILayer fills. APILayer offers a suite of plug-and-play APIs for live data: weather, exchange rates, IP geolocation, phone validation, and dozens more. Connect one of them to Claude Code and your terminal-based AI assistant suddenly has live data superpowers.
In this guide we’ll connect Weatherstack, APILayer’s weather API, to Claude Code in about fifteen minutes. You’ll end with Claude Code fetching real, live weather data straight from your terminal.
Table of Contents
Key takeaways
- APILayer is a platform of ready-to-use APIs that give Claude Code access to real-time data outside its training set.
- The integration is just three pieces: an API key, an environment variable, and a prompt telling Claude Code which endpoint to call.
- The full walkthrough takes 10 to 15 minutes and needs no SDK, just a terminal, a key, and Claude Code.
- Free-tier Weatherstack is HTTP-only and caps you at 100 requests per month, which is plenty for development.
- APILayer is working on MCP (Model Context Protocol) support, which will make these integrations even smoother in the near future.
Why Claude Code needs an API for real-time data
Claude Code lives in your terminal and can edit files, run shell commands, and write code in any language. What it can’t do on its own is reach out to the live internet for fresh, structured data. You can paste in a CSV, but you can’t ask it “What’s the temperature in Lisbon right now?” and get a useful answer without giving it a way to call an API.
Plugging it into Weatherstack via APILayer fixes that for weather. The same pattern works for every other API like currency, IP geolocation, phone validation, stock prices, and so on. Once you’ve done it once, you’ve done it for all of them.
If APIs in general are still new territory, What and How about API Call? is a solid five-minute primer.
What you’ll need
A short checklist before you start:
- An APILayer account. Free, no credit card. Sign up at apilayer.com.
- A Weatherstack API key. You’ll generate this inside the APILayer dashboard once you subscribe to Weatherstack’s free plan.
- Claude Code installed and working. Run claude –version to confirm. If you don’t have it yet, install it with npm install -g @anthropic-ai/claude-code (Node.js 18+ required), or use the native installer described in the official Claude Code docs.
- A terminal. Any one will do: Terminal.app, iTerm2, Windows Terminal, or the integrated terminal inside VS Code.
That’s it. No SDKs, no client libraries, no extra dependencies.
Step 1: Get your Weatherstack API key from APILayer
Head to the APILayer products page and search for Weatherstack. Subscribe to the free plan (100 requests per month, which is more than enough to follow along).
Once subscribed, your API key shows up in your APILayer dashboard. Copy it. Treat it like a password. Anyone with this key can use up your monthly quota.
If you want a quick refresher on what an API key actually is and how to keep it safe, What Is API Access? API Keys, Authentication, Rate Limits, and Common Errors Explained covers it in about ten minutes.
The full endpoint reference, including optional parameters and response fields, is in the Weatherstack API documentation.
Step 2: Set the key as an environment variable
The easiest way to leak an API key is to hardcode it into a script and push it to GitHub. Don’t. Export it as an environment variable instead:
export WEATHERSTACK_API_KEY="your_actual_key_here"
This makes the key available to anything you launch from this shell, including Claude Code. To make it persistent across terminal restarts, add the same line to your ~/.zshrc or ~/.bashrc (or the equivalent for your shell), then reload it with source ~/.zshrc.
Quick sanity check:
echo $WEATHERSTACK_API_KEY
If your key prints back, you’re good.
Step 3: Launch Claude Code
In your terminal, cd into any working directory (a fresh scratch folder is fine) and run:
claude
You’ll land in an interactive Claude Code session. From here you can talk to it the way you’d talk to a colleague: natural language in, code and tool calls out.
Step 4: Ask Claude Code to call the Weatherstack API
This is where it gets fun. Paste in something like:
Write a short Python script that calls the Weatherstack current weather endpoint for New York and prints the response as formatted JSON. Read the access key from the WEATHERSTACK_API_KEY environment variable. Endpoint reference: http://api.weatherstack.com/current?access_key=YOUR_KEY&query=New York. After writing it, run it.
Claude Code will draft a script, ask permission to write it to disk, and then ask permission to run it. The script it generates typically looks something like this:
import json
import os
import urllib.parse
import urllib.request
API_KEY = os.environ["WEATHERSTACK_API_KEY"]
QUERY = "New York"
url = (
"http://api.weatherstack.com/current"
f"?access_key={API_KEY}"
f"&query={urllib.parse.quote(QUERY)}"
)
with urllib.request.urlopen(url) as response:
data = json.loads(response.read().decode())
if "error" in data:
raise SystemExit(f"Weatherstack error: {data['error']}")
print(json.dumps(data, indent=2))
Approve the run. Within a second or two, Claude Code prints the live JSON response from Weatherstack right into your terminal.
Step 5: Read the live response
The response you get back follows Weatherstack’s three-section structure: a request block echoing your query, a location block with geographic metadata, and a current block with the actual weather data. A typical response looks like this:
{
"request": {
"type": "City",
"query": "New York, United States of America",
"language": "en",
"unit": "m"
},
"location": {
"name": "New York",
"country": "United States of America",
"region": "New York",
"lat": "40.714",
"lon": "-74.006",
"timezone_id": "America/New_York",
"localtime": "2026-05-22 09:42",
"localtime_epoch": 1747906920,
"utc_offset": "-4.0"
},
"current": {
"observation_time": "01:42 PM",
"temperature": 18,
"weather_code": 116,
"weather_descriptions": ["Partly cloudy"],
"wind_speed": 13,
"wind_dir": "SW",
"pressure": 1014,
"humidity": 67,
"feelslike": 18,
"uv_index": 6,
"visibility": 16,
"is_day": "yes"
}
}
That’s the entire integration. Claude Code now has live weather data, and so do you. From here you can extend the same prompt to compare cities, persist responses to a SQLite database, or chart the data. The API call is the only piece it was missing.
For a deeper walkthrough of Weatherstack’s full feature set, including forecast and historical endpoints, see How to Build a Real-Time Weather Dashboard Using the Weatherstack API.
Get Your Free
Weather API Key!
Weatherstack
Access real-time and historical weather data for any location worldwide. Join over 75,000 developers and businesses using Weatherstack APIs.
Get Your Free API KeyFree Plan Available
Best practices
A few things worth knowing before you build on top of this.
The free plan is HTTP only. Change the URL to https:// and you’ll get an error back saying SSL isn’t supported on your subscription. HTTPS is available on Weatherstack’s paid plans, which start at $9.99 a month. For local development it’s a non-issue; just don’t ship an HTTP integration to production.
Errors come back as HTTP 200 with an error body. Weatherstack returns a 200 status code even on auth or quota failures, with the error wrapped inside the JSON. The example script above handles this by checking for an error key before assuming the response is valid weather data. Tell Claude Code to add that check whenever you have it write a new client.
Environment variables don’t cross terminals. If you export your key in one terminal and start Claude Code in another, it won’t see the variable. Either put the export in your shell’s rc file, or start Claude Code from the same shell where you exported the key.
The free quota is 100 requests per month. That sounds tight but is plenty for development. If Claude Code starts looping, or you build a test that re-fetches the endpoint in a tight loop, you can burn through the quota quickly. Cache aggressively during development.
What’s next: MCP support on APILayer
The workflow above is the right pattern today, and it works for any APILayer API. Swap the Weatherstack endpoint for currency data, IP geolocation, or phone validation, and the rest of the steps are the same.
What’s coming is even smoother. APILayer is working on MCP (Model Context Protocol) support. MCP is the open standard for connecting AI assistants like Claude to external tools, and once APILayer’s MCP server lands, you won’t need to hand Claude Code an endpoint and an example URL at all. The APIs will register as native tools the assistant can discover and call directly.
We’ll cover the full MCP setup in a dedicated post when it’s ready. If you want to read more on how MCP changes AI-assisted developer workflows in the meantime, MCP vs CLI: Which Is Better for AI-Assisted Developer Workflows? is a good place to start.
Try it yourself
Ready to give Claude Code access to real-time data? Sign up for a free Weatherstack API key on APILayer, no credit card required, and try this walkthrough yourself. Once you’ve got weather working, explore the full set of APILayer APIs to connect currency data, IP geolocation, phone validation, and more. Get your free API key here
Frequently asked questions
1). Does Claude Code support external APIs out of the box?
Claude Code can write and run any code you give it permission to run, which means it can call any HTTP API the moment you give it a key and an endpoint. There’s no built-in API catalog. You bring the credentials and the URL, and Claude Code does the rest.
2). Is APILayer free to use with Claude Code?
Yes. APILayer includes free tiers for most APIs, including Weatherstack’s 100 requests per month. You only pay if you exceed the free quota or need premium features like HTTPS, higher rate limits, or forecast and historical endpoints.
3). Why use APILayer instead of calling Weatherstack directly?
APILayer is the official distribution channel for Weatherstack and dozens of other production APIs. One APILayer account gives you unified billing, a single dashboard, and consistent key management across every API you subscribe to, instead of juggling separate accounts and bills per vendor.
4). Can I use the same setup for currency or IP geolocation APIs on APILayer?
Yes. The pattern is identical: subscribe on APILayer, export the key as an environment variable, point Claude Code at the relevant endpoint, and let it write the request. Only the URL and the response schema change.

