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.0.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.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: semanticapi_langchain-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 fa04a24d0c644cd2cde1651126f32cbb423eee5e9209c14e0419351bd96cbad7
MD5 555e5409a2fde587701be67d655be805
BLAKE2b-256 c50e4f4afac4993d64437532bca7f11fb401988ec00f49610a702069a638d150

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for semanticapi_langchain-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bb3ee0370e1486991ad0dac95447bfbc13f56f946f601c69839390eaac0d0ea
MD5 cbefe84d58477e685786fe13e35fc82b
BLAKE2b-256 98606049774521137cf906d6f6b1ac580057bcf8062c309cf94525e4f009dadc

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