Skip to main content

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.

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.

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
semanticapi_search Search and discover available API capabilities

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semanticapi_langchain-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semanticapi_langchain-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file semanticapi_langchain-0.1.1.tar.gz.

File metadata

  • Download URL: semanticapi_langchain-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for semanticapi_langchain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1a2fda57df4f9993ca3edfeaca396e4002746999b1a5fa1b24b0d84aa96d592c
MD5 0c3e178cb0d537695d75cb1a22d19127
BLAKE2b-256 f77ded00d6065a3fb355c1597cf49181d16e13667b4a4688980a5f4fa3efa862

See more details on using hashes here.

File details

Details for the file semanticapi_langchain-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for semanticapi_langchain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cac92307463d7cc026c931f564d396e2b8b44ef337b3dcafea361172ba675483
MD5 ea84c9efb903b79fa1cbedf410d63a70
BLAKE2b-256 7043abffcfbbd5a270aafb1934b065b0d14c0ae51ea6bc021e7b06a47017fec2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page