LangChain Integration
Build powerful AI applications with LangChain using APIVerve's 300+ APIs as tools. Our official LangChain toolkit lets you easily integrate email validation, data enrichment, and hundreds of other APIs into your agents and chains.
What is the LangChain Integration?
The LangChain integration provides a toolkit that wraps all APIVerve APIs as LangChain-compatible tools. This allows you to use any of our 300+ APIs in your LangChain agents, chains, and workflows.
Key features:
- 300+ API Tools: Every APIVerve API is available as a LangChain tool
- Agent-Ready: Tools work with LangChain's agent framework out of the box
- Type-Safe: Full type hints and parameter validation
- Easy Setup: Just install and provide your API key
The LangChain integration is currently available for Python only. For other languages, use our REST API or GraphQL endpoint directly.
Installation
Install the package using pip:
pip install langchain-apiverveRequirements
- Python 3.8 or higher
- LangChain 0.1.0 or higher
- An APIVerve API key (get one free)
Authentication
You can provide your API key in two ways:
Option 1: Direct Parameter
Pass your API key directly when creating the toolkit:
toolkit = APIVerveToolkit(api_key="your-apiverve-api-key")Option 2: Environment Variable
Set your API key as an environment variable:
# Set your API key as an environment variable
export APIVERVE_API_KEY="your-apiverve-api-key"Then initialize the toolkit without parameters:
from langchain_apiverve import APIVerveToolkit
# API key is automatically read from APIVERVE_API_KEY environment variable
toolkit = APIVerveToolkit()We recommend using environment variables in production to avoid hardcoding your API key in source code.
Basic Usage
Using with Agents
The most common use case is adding APIVerve tools to a LangChain agent. This allows the agent to decide when to use which API based on the user's query.
from langchain_apiverve import APIVerveToolkit
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_openai import ChatOpenAI
# Initialize the toolkit with your API key
toolkit = APIVerveToolkit(api_key="your-apiverve-api-key")
# Get all available tools
tools = toolkit.get_tools()
# Create an agent with the tools
llm = ChatOpenAI(model="gpt-4")
agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
# Run the agent
result = agent_executor.invoke({"input": "Validate the email address [email protected]"})
print(result)Using Specific Tools
You can also get specific tools by API name and use them directly:
from langchain_apiverve import APIVerveToolkit
toolkit = APIVerveToolkit(api_key="your-apiverve-api-key")
# Get specific tools by API name
email_tool = toolkit.get_tool("emailvalidation")
dns_tool = toolkit.get_tool("dnslookup")
# Use tools directly
result = email_tool.invoke({"email": "[email protected]"})
print(result)Using in Chains
You can use APIVerve tools within LangChain chains to build data pipelines:
from langchain_apiverve import APIVerveToolkit
from langchain.chains import LLMChain
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
toolkit = APIVerveToolkit(api_key="your-apiverve-api-key")
ip_tool = toolkit.get_tool("iplookup")
# Get IP geolocation data
ip_data = ip_tool.invoke({"ip": "8.8.8.8"})
# Use the data in a chain
llm = ChatOpenAI()
prompt = PromptTemplate.from_template(
"Based on this IP data: {ip_data}, summarize the location information."
)
chain = LLMChain(llm=llm, prompt=prompt)
summary = chain.run(ip_data=ip_data)
print(summary)Available APIs
All 300+ APIVerve APIs are available as tools. Some popular categories include:
- Validation: Email, phone, URL, credit card validation
- Data Enrichment: IP lookup, domain info, company data
- Text Processing: Sentiment analysis, language detection, summarization
- Conversion: Currency, units, file formats
- Utilities: QR codes, screenshots, PDF generation
Browse all available APIs in our API Reference or the API Marketplace.
Example Use Cases
Email Validation Agent
Build an agent that validates email addresses before adding them to your CRM. The agent can check if emails are valid, detect disposable addresses, and verify domains.
Data Enrichment Pipeline
Create a chain that takes raw data and enriches it with additional context. For example, take an IP address and get geolocation, ISP info, and threat intelligence.
Content Generation Assistant
Build an assistant that generates QR codes, screenshots, and PDFs on demand. The agent decides which tool to use based on the user's request.
Research Agent
Create an agent that can look up domain information, check DNS records, and gather WHOIS data to help with research tasks.
Best Practices
- Limit Tool Selection: Only load the tools your agent needs to reduce token usage
- Handle Errors: Wrap tool calls in try/catch blocks for graceful error handling
- Monitor Usage: Check your token balance in the APIVerve dashboard
- Cache Results: Cache API responses when appropriate to reduce costs
- Use Streaming: For long-running operations, consider async execution
Troubleshooting
API Key Not Found
If you get an authentication error, ensure your API key is correctly set either as a parameter or in the APIVERVE_API_KEY environment variable.
Tool Not Found
If get_tool() returns None, check that the API name matches exactly. API names are lowercase without spaces (e.g., "emailvalidation", "iplookup").
Rate Limits
If you're hitting rate limits, consider upgrading your plan or adding delays between API calls. Check your current limits in the dashboard.
Insufficient Tokens
If you run out of tokens, you'll need to purchase more or upgrade your plan. Monitor your usage in the APIVerve Dashboard.
Additional Resources
- PyPI Package - Installation and version info
- GitHub - Source code and issues
- API Marketplace - Browse all 300+ APIs
- API Reference - Detailed API documentation
- LangChain Docs - LangChain documentation
Was this page helpful?
Help us improve our documentation
