Skip to main content

semanticapi-langchain

LangChain integration for Semantic API — find the right API for any task using natural language.

PyPI Python License: MIT

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

Metadata

Release files for semanticapi-langchain 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for semanticapi-langchain 0.1.2
File Size Uploaded
semanticapi_langchain-0.1.2.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for semanticapi-langchain 0.1.2
File Interpreter ABI Platform
semanticapi_langchain-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / semanticapi_langchain-0.1.2.tar.gz

Download URL semanticapi_langchain-0.1.2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ecdff63756bc0c9598353114f341cd35d50bba89441fddb6f5e3ad4d06c3154c
BLAKE2b-256 checksum
How to use checksums
f356e50e5f7934781d47317e193418cf10da94a01eb2c27d9f008aca7dffb2d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / semanticapi_langchain-0.1.2-py3-none-any.whl

Download URL semanticapi_langchain-0.1.2-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e801d71db2b6b415ce57ea9f4073b37115210133410d950efd5eae197124fd3
BLAKE2b-256 checksum
How to use checksums
d06c9d1058ee6b78f2a9716d4b12c6e8f487f9bd1dfa7987b0dec4e7b8a7d243
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page