Open-Source Models — Python LangChain
Use the nacho-api-langchain Python package to give any LLM access to Cardano blockchain data via function calling.
The nacho-api-langchain Python package provides a NachoAPIToolkit that works with LangChain, LlamaIndex, and any framework that supports OpenAI-compatible function calling — including LLaMA, Mistral, Gemma, Qwen, and other open-source models.
Installation
pip install nacho-api-langchainLangChain agent
from nacho_api_langchain import NachoAPIToolkit
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI # or any LangChain-compatible LLM
toolkit = NachoAPIToolkit(api_key="napi_your_key_here")
tools = toolkit.get_tools()
llm = ChatOpenAI(model="gpt-4o") # swap for any LangChain LLM
agent = initialize_agent(
tools,
llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True
)
response = agent.run("What is the current ADA price and which epoch are we in?")LlamaIndex agent
from nacho_api_langchain import NachoAPIToolkit
from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI
toolkit = NachoAPIToolkit()
tools = toolkit.get_llamaindex_tools()
llm = OpenAI(model="gpt-4o")
agent = ReActAgent.from_tools(tools, llm=llm, verbose=True)
response = agent.chat("Show me the last 3 blocks on mainnet")Direct tool usage
Call tools directly without an agent framework:
from nacho_api_langchain import NachoAPIToolkit
import json
toolkit = NachoAPIToolkit()
tools = {t.name: t for t in toolkit.get_tools()}
# Get ADA price
price_data = json.loads(tools["nacho_get_price"].run({}))
print(f"ADA price: ${price_data['ada_usd']}")
# Get network stats
stats = json.loads(tools["nacho_get_network_stats"].run({"network": "mainnet"}))
print(f"Epoch {stats['epochNo']}, block {stats['blockHeight']}")
# Look up a pool
pool = json.loads(tools["nacho_get_pool_info"].run({"pool_id": "pool1dhug..."}))
print(f"Pool {pool['ticker']}: {pool['margin'] * 100:.1f}% margin")Configuration
from nacho_api_langchain import NachoAPIToolkit
toolkit = NachoAPIToolkit(
api_key="napi_xxx", # Optional — for GraphQL/submit
base_url="https://api.nacho.builders", # Optional — default shown
default_network="mainnet", # Optional — "mainnet" or "preprod"
)Available tools (16)
All tools are prefixed with nacho_. All tools require an API key — sign up free to get one automatically.
| Tool | Input | Description |
|---|---|---|
nacho_get_price | — | ADA/USD exchange rate |
nacho_get_protocol_params | — | Network protocol parameters |
nacho_get_pool_status | — | NACHO pool live stats |
nacho_get_pool_info | pool_id | Pool metadata and fees |
nacho_get_stake_account | address | Delegation and rewards |
nacho_get_tx_status | tx_hash | Transaction confirmation |
nacho_get_network_stats | network | Epoch, supply, active stake |
nacho_get_blocks | network, page, limit | Recent blocks |
nacho_get_block | network, id | Block by number or hash |
nacho_get_transaction | network, hash | Full transaction details |
nacho_get_address | network, address | Address balance and tokens |
nacho_get_address_utxos | network, address, page | Address UTxOs |
nacho_get_pool_detail | network, pool_id | Full pool details |
nacho_get_dreps | network, page, active_only | Governance DReps |
nacho_graphql_query | query, variables | Custom GraphQL over the full DB-Sync schema (all tiers) |
nacho_submit_transaction | cbor_hex | Submit transaction — free: 10 tx/hr, paid: unlimited |
OpenAI function definitions (without LangChain)
Use the raw function definitions with any OpenAI-compatible client:
from nacho_api_langchain import get_openai_function_definitions
functions = get_openai_function_definitions()
# Pass to any OpenAI-compatible chat completion callRequirements
- Python 3.10+
langchain-core>=0.2httpx>=0.27pydantic>=2.0
Testnet
Set default_network="preprod" to use the Cardano pre-production testnet (tADA, not real ADA).
Was this page helpful?