Your AI agent can’t check crypto prices. Ask it what Bitcoin is worth right now and it answers instantly, with a number that’s wrong, stale or both, stated as confidently as if it were live.
Tool use fixes this. coinlayer is a real-time cryptocurrency API your agent can call: one JSON schema, one HTTP request, and it answers from real data instead of a guess.
Table of Contents
Key Takeaways
- LLMs don’t know live prices. Without a crypto price API to call, they state a confident, stale number.
- coinlayer’s /live endpoint returns real-time rates for 385+ coins as plain JSON, authenticated with a single access_key.
- A tool definition is just a JSON schema. One field is enough to let the model call get_crypto_price correctly.
- The Free plan gives you 100 requests a month over HTTPS for non-commercial use. Conversion, non-USD targets and commercial use start on Starter.
How Do I Give My AI Agent Live Crypto Prices?
Ask most models for BTC’s price with no tool attached and you’ll get an answer that sounds exact: a specific dollar figure, stated flatly, anchored to whatever the price was near the model’s training cutoff. There’s no warning that it’s stale, because the model has no way to know.
The fix is to define a tool backed by a real-time crypto API, pass the model’s tool call to that API and feed the response back. With coinlayer, that’s a JSON schema, one HTTP request and a short loop. No exchange accounts, no WebSocket feeds and no rate-limit plumbing to build yourself.
What coinlayer Gives You
coinlayer tracks real-time and historical rates for 385+ cryptocurrencies from 25+ exchanges, returned as plain JSON, with history back to 2011. Authentication is a single access_key query parameter: no OAuth, no signed requests. All plans use HTTPS.
Plans, from the product page (checked 1 Dec 2026):
Plan | Price | Requests per month | Adds | Updates |
|---|---|---|---|---|
Free | $0 | 100 | Live and historical rates, non-commercial use | Hourly |
Starter | $9.99/month | 5,000 | Commercial use, conversion endpoint | Hourly |
Professional | $39.99/month | 30,000 | Time-frame queries | Every 10 minutes |
Enterprise | $79.99/month | 100,000 | Change queries | Every 60 seconds |
This build uses two endpoints:
- /live: the current rate for one or more coins, in USD by default.
- /list: every symbol coinlayer recognizes, so you can validate a symbol before spending a request on it.
A quick check against /list before your first real call:
curl “https://api.apilayer.net/coinlayer/list?access_key=YOUR_ACCESS_KEY”
Endpoints at a Glance
Endpoint | What it returns | Plan |
|---|---|---|
/live | Current rate for one or more coins | Free and above |
/list | Every symbol coinlayer recognizes | Free and above |
/YYYY-MM-DD | Rates on a past date, back to 2011 | Free and above |
/convert | Direct conversion between two currencies | Starter and above |
/timeframe | Daily rates across a date range | Professional and above |
/change | Rate change (start, end, %) over a period | Enterprise |
The full parameter reference is in the coinlayer API documentation. For more on keys, retries and rate limits, see what API access means: keys, authentication, rate limits and common errors.
Building the Tool
Three steps: define the tool, fetch the data, wire it into the loop.
Step 1: Define the tool
This is the contract you hand to the model. It names the function, says what it returns and constrains the input so the model can’t invent fields you don’t support.
{
"type": "function",
"function": {
"name": "get_crypto_price",
"description": "Get the latest USD price for one or more cryptocurrencies.",
"parameters": {
"type": "object",
"properties": {
"symbols": {
"type": "string",
"description": "Comma-separated crypto symbols, e.g. BTC or BTC,ETH,LTC"
}
},
"required": ["symbols"]
}
}
}
Your handler returns a JSON string of rates keyed by symbol, such as {“BTC”: 61159.55}. That’s exactly the rates object /live gives you in Step 2, so there’s no reshaping to do.
Step 2: Call the coinlayer /live endpoint
curl “https://api.apilayer.net/coinlayer/live?access_key=YOUR_ACCESS_KEY&symbols=BTC,ETH,LTC”
In your agent’s code, that becomes a function that checks coinlayer accepted the request before trusting the response:
import json
import os
import requests
COINLAYER_KEY = os.environ["COINLAYER_ACCESS_KEY"]
def get_crypto_price(symbols):
r = requests.get(
"https://api.apilayer.net/coinlayer/live",
params={"access_key": COINLAYER_KEY, "symbols": symbols},
timeout=10,
)
data = r.json()
if not data.get("success"):
return json.dumps({"error": data.get("error", "request failed")})
return json.dumps(data["rates"])
A real call on 1 December 2026 returned:
{
"success": true,
"terms": "https://coinlayer.com/terms",
"privacy": "https://coinlayer.com/privacy",
"timestamp": 1796130326,
"target": "USD",
"rates": {
"BTC": 61159.548333,
"ETH": 1713.896333,
"LTC": 43.4336
}
}
Everything the agent needs is in rates. The timestamp tells you when the rates were collected; on Free and Starter they update hourly, not tick by tick.
Step 3: Wire it into the agent loop
Set both keys as environment variables:
export COINLAYER_ACCESS_KEY=”your_coinlayer_key”
export OPENAI_API_KEY=”your_openai_key”
Save this as agent.py. It’s the whole integration: tool schema, the fetch function from Step 2 and the loop that passes results back to the model.
import json
import os
import requests
from openai import OpenAI
COINLAYER_KEY = os.environ["COINLAYER_ACCESS_KEY"]
client = OpenAI() # reads OPENAI_API_KEY
TOOLS = [{
"type": "function",
"function": {
"name": "get_crypto_price",
"description": "Get the latest USD price for one or more cryptocurrencies.",
"parameters": {
"type": "object",
"properties": {
"symbols": {
"type": "string",
"description": "Comma-separated symbols, e.g. BTC or BTC,ETH,LTC"
}
},
"required": ["symbols"]
}
}
}]
def get_crypto_price(symbols):
r = requests.get(
"https://api.apilayer.net/coinlayer/live",
params={"access_key": COINLAYER_KEY, "symbols": symbols},
timeout=10,
)
data = r.json()
if not data.get("success"):
return json.dumps({"error": data.get("error", "request failed")})
return json.dumps(data["rates"])
messages = [{"role": "user", "content": "What is Bitcoin worth right now?"}]
response = client.chat.completions.create(model="gpt-4o", tools=TOOLS, messages=messages)
msg = response.choices[0].message
if msg.tool_calls:
messages.append(msg) # add the assistant's tool request once
for tool_call in msg.tool_calls:
args = json.loads(tool_call.function.arguments)
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": get_crypto_price(args["symbols"]),
})
final = client.chat.completions.create(model="gpt-4o", messages=messages)
print(final.choices[0].message.content)
else:
print(msg.content)
Run it:
pip3 install openai requests
python3 agent.py
Ask “What’s Bitcoin worth right now?” and the model calls get_crypto_price with {“symbols”: “BTC”}, gets the rates back as a tool result and writes a plain-language answer from the real number.
Seeing It Work
Two questions, answered from the response above:
You: What’s Bitcoin worth right now? Agent calls: get_crypto_price(symbols=”BTC”) Agent replies: Bitcoin (BTC) is trading at $61,159.55, based on the latest coinlayer update.
You: How do BTC, ETH and LTC compare right now? Agent calls: get_crypto_price(symbols=”BTC,ETH,LTC”) Agent replies: BTC is $61,159.55, ETH is $1,713.90 and LTC is $43.43, so BTC is worth roughly 36x ETH and 1,408x LTC at these rates.
Same tool, two different questions. The model decides when to call it and how to phrase the answer; your job stops at returning honest data.
Using the Same Tool With Claude
get_crypto_price doesn’t change between frameworks. Only the tool schema’s shape and how you return the result do. Here’s the same tool for the Anthropic Messages API (set ANTHROPIC_API_KEY instead of OPENAI_API_KEY), saved as agent2.py:
import os
import anthropic
# reuse get_crypto_price() from Step 2
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY
tools = [{
"name": "get_crypto_price",
"description": "Get the latest USD price for one or more cryptocurrencies.",
"input_schema": {
"type": "object",
"properties": {
"symbols": {
"type": "string",
"description": "Comma-separated crypto symbols, e.g. BTC or BTC,ETH,LTC"
}
},
"required": ["symbols"],
},
}]
question = {"role": "user", "content": "What's Bitcoin worth right now?"}
response = client.messages.create(
model="claude-opus-4-5", max_tokens=1024, tools=tools, messages=[question],
)
results = [
{"type": "tool_result", "tool_use_id": block.id,
"content": get_crypto_price(block.input["symbols"])}
for block in response.content
if block.type == "tool_use" and block.name == "get_crypto_price"
]
if results:
final = client.messages.create(
model="claude-opus-4-5", max_tokens=1024, tools=tools,
messages=[question,
{"role": "assistant", "content": response.content},
{"role": "user", "content": results}],
)
print(final.content[0].text)
else:
print(response.content[0].text)
The field name changes from parameters to input_schema, and the call comes back as a tool_use content block instead of a tool_calls list, but the function from Step 2 is reused as is. The same pattern works with LangChain’s @tool decorator or any framework with function calling.
Limits to Design Around
- Free is non-commercial. An agent in a product you sell needs Starter or above.
- USD only on Free. The target parameter for other currencies, and /convert, start on Starter.
- 100 requests a month on Free. An agent that calls the tool on every message uses that up fast, so cache.
- Errors are normal responses. get_crypto_price already checks success, so a bad symbol or expired key comes back as a clean error object instead of a crash.
Production Checklist
- Cache responses for up to an hour on Free and Starter: rates update hourly, so calling /live more often spends requests without new data.
- Keep the access_key on the server. Never ship it in client-side JavaScript or a mobile app.
- Treat success: false as a normal code path. Expired keys and bad symbols return error objects, not HTTP failures.
- Add a retry with backoff for network failures, so one dropped request doesn’t take down the agent’s turn.
- Track usage against your monthly cap, and cache per symbol to stretch it.
Extending the Tool
Once /live works, the historical endpoint (/YYYY-MM-DD) prices a coin on any day back to 2011, and /convert (Starter and above) turns an amount in one currency into another without you doing the maths. Add either as a second tool and let the model choose. Parameters for both are in the coinlayer API documentation.
For agent design beyond crypto, see making your API agent-ready. For the same tool with stocks instead of coins, the marketstack and Claude tool-use walkthrough follows the same pattern.
Use cases:
- /live: an agent that answers “what’s X worth right now”.
- Historical: an agent that answers “what was BTC worth on this date” or backtests against past prices.
- /convert: an agent that computes swap amounts directly, without combining two /live calls.
coinlayer’s Free plan gives you 100 requests a month, enough to prototype your agent’s crypto tool today. Get a free coinlayer API key.
Explore APILayer Products
Discover APIs for geolocation, finance, aviation, weather, web scraping, AI, and more. Browse APILayer's product catalog to find the right APIs for your application and integrate the data and functionality your project needs.
Explore APILayer ProductsFind the right tools to start building.
FAQs
Why does an AI model give the wrong crypto price?
Live prices aren’t in its training data. Without a tool to call, it guesses from whatever prices it saw during training and still sounds certain, with no warning that the number is stale.
How do I give an AI agent live crypto prices?
Define a tool backed by coinlayer’s /live endpoint, call the API when the model requests the tool, and return the JSON rates to the model as a tool result. The model then answers from real data.
Is coinlayer free to use?
Yes, for non-commercial use: the Free plan gives you 100 requests a month over HTTPS, with live and historical rates in USD. Conversion, other target currencies and commercial use start on Starter at $9.99 a month.
Which coinlayer endpoint returns the latest price?
/live, with your access_key and a symbols parameter such as BTC,ETH,LTC. It returns a rates object keyed by symbol, plus a timestamp showing when the rates were collected.
Can I use this with Claude or LangChain instead of OpenAI?
Yes. get_crypto_price stays the same; only the tool-registration format changes per framework, as the Claude example above shows. Any model with function or tool calling follows the same pattern.
Currency API
Stay up to date and read the latest finance articles by apilayer.com. Read today to know more!
Related categories