LangChain integration for Semantic API — find the right API for any task using natural language
Project description
semanticapi-langchain
LangChain integration for Semantic API — find the right API for any task using natural language.
What is Semantic API?
Semantic API matches natural language queries to real API endpoints. Ask "send an SMS" and get back the best provider, endpoint, parameters, and auth docs — instantly.
✨ Auto-Discover & Auto-Heal
Auto-Discover: Your agent can query any API — even ones not in the catalog. Semantic API automatically finds the docs, generates a provider config, and returns endpoint details. No manual setup.
Auto-Heal: If an API's config goes stale (endpoints move, versions change), Semantic API detects the failure, re-discovers from current docs, and retries — all transparently. Your agent never sees a stale endpoint.
Built-in Retry: All tools include exponential backoff with retry logic for rate limits and transient errors — production-ready out of the box.
Installation
pip install semanticapi-langchain
Quick Start
from semanticapi_langchain import SemanticAPIToolkit
# Create toolkit (uses SEMANTICAPI_API_KEY env var)
toolkit = SemanticAPIToolkit(api_key="sapi_your_key")
tools = toolkit.get_tools()
# Use the query tool directly
query_tool = tools[0]
result = query_tool.run("send an SMS")
print(result)
Tools
| Tool | Description |
|---|---|
semanticapi_query |
Find the best API for a task described in plain English (with auto-discover) |
semanticapi_search |
Search and discover available API capabilities |
semanticapi_discover |
Deep-discover a specific provider by name (auto-discovers unknown APIs) |
With a LangChain Agent
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from semanticapi_langchain import SemanticAPIToolkit
toolkit = SemanticAPIToolkit()
tools = toolkit.get_tools()
llm = ChatOpenAI(model="gpt-4o-mini")
prompt = ChatPromptTemplate.from_messages([
("system", "You find APIs for tasks. Use semanticapi tools to discover them."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
response = executor.invoke({"input": "How do I send an email programmatically?"})
print(response["output"])
Using the Wrapper Directly
from semanticapi_langchain import SemanticAPIWrapper
api = SemanticAPIWrapper(api_key="sapi_your_key")
# Query for an API
result = api.query("send an SMS")
# Search capabilities
results = api.search("weather")
# List providers
providers = api.list_providers()
# Async support
result = await api.aquery("send an SMS")
Configuration
| Parameter | Env Var | Description |
|---|---|---|
api_key |
SEMANTICAPI_API_KEY |
Your Semantic API key |
base_url |
— | Override API base URL (default: https://semanticapi.dev/api) |
timeout |
— | Request timeout in seconds (default: 30) |
Development
git clone https://github.com/semanticapi/semanticapi-langchain.git
cd semanticapi-langchain
pip install -e ".[dev]"
pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file semanticapi_langchain-0.1.2.tar.gz.
File metadata
- Download URL: semanticapi_langchain-0.1.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecdff63756bc0c9598353114f341cd35d50bba89441fddb6f5e3ad4d06c3154c
|
|
| MD5 |
777cb2277d8add8407d411a648983464
|
|
| BLAKE2b-256 |
f356e50e5f7934781d47317e193418cf10da94a01eb2c27d9f008aca7dffb2d6
|
File details
Details for the file semanticapi_langchain-0.1.2-py3-none-any.whl.
File metadata
- Download URL: semanticapi_langchain-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e801d71db2b6b415ce57ea9f4073b37115210133410d950efd5eae197124fd3
|
|
| MD5 |
c18ff9a55620b556dd11fcb7408c072f
|
|
| BLAKE2b-256 |
d06c9d1058ee6b78f2a9716d4b12c6e8f487f9bd1dfa7987b0dec4e7b8a7d243
|