Skip to main content

knowapi-langchain

Official records for AI agents, with the source on every answer: KnowAPI tools for LangChain and LangGraph.

from knowapi_langchain import KnowAPIToolkit

tools = KnowAPIToolkit().get_tools()       # core tools; KnowAPIToolkit(profile="all") for every tool

With LangChain agents (built on LangGraph; needs langchain and a model package such as langchain-openai):

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI

agent = create_agent(ChatOpenAI(model="gpt-4o-mini"), tools)
reply = agent.invoke({"messages": [("user", "Is there a shortage of amoxicillin right now? Cite the source.")]})
print(reply["messages"][-1].content)

Without LangChain:

from knowapi_langchain import KnowAPI
kn = KnowAPI()
kn.ask("Which medicines are currently in shortage?")
kn.request_data("Daily FDA drug recalls for pet food with brand and reason")  # build it; earn when others use it

Free to start: a starter credit shared across every API, then pay per call. A call that returns no records is not charged. The current terms are at https://api.knowapi.dev/v2/free-allowance.

Usage telemetry

Requests send User-Agent: knowapi-langchain/<version> (langchain) (or (direct) for the plain client): SDK name, version and framework, nothing about you or your machine. KnowAPI uses it to count SDK usage.

The tool list is read live from https://api.knowapi.dev/mcp. Docs for agents: https://api.knowapi.dev/llms.txt.

Paying as an agent (optional x402)

Agents without native x402 support can pay from a wallet you control, within limits you set. Nothing is paid unless you pass a wallet, and your key's free allowance and prepaid credit are always used first.

import os
from eth_account import Account                      # pip install "knowapi-langchain[wallet]"
from knowapi_langchain import KnowAPI, KnowAPIToolkit, eth_account_wallet, SpendLimitError

kn = KnowAPI(
    api_key=os.environ.get("KNOWAPI_KEY"),             # optional: keeps your free allowance and credit
    wallet=eth_account_wallet(Account.from_key(os.environ["AGENT_WALLET_KEY"])),
    limits={"per_call_usd": 0.05, "daily_usd": 2, "total_usd": 20},
    auto_top_up={"usd": 5},                            # optional: refill the key once instead of paying per call
)
print(kn.quote(api_id, {"state": "CA"}))              # free: what this exact call costs
data = kn.query(api_id, {"state": "CA"})               # pays the 402 only if needed; data["paid"] says what was paid
tools = KnowAPIToolkit(client=kn).get_tools()          # query_api pays the same way when it reports payment_required
  • Limits are checked before anything is signed (SpendLimitError); pass store to keep totals across restarts.
  • No double charges: a retry after a lost response re-sends the same signed authorization (it can settle only once); a new payment is signed only after the server says the previous one was not taken; an unknown outcome stops with PaymentOutcomeUnknownError.
  • Insufficient funds stop with InsufficientFundsError. Only USDC on Base is paid by default (networks); you can pin the receiver (pay_to). Empty answers are never charged.
  • Any wallet works if it has address and sign_typed_data(typed_data) -> hex signature.

Metadata

Release files for knowapi-langchain 0.2.0

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

Source distribution (sdist)

Source distribution for knowapi-langchain 0.2.0
File Size Uploaded Provenance Actions
knowapi_langchain-0.2.0.tar.gz 14.6 kB Without provenance Details for knowapi_langchain-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for knowapi-langchain 0.2.0
File Interpreter ABI Platform Actions
knowapi_langchain-0.2.0-py3-none-any.whl Python 3 none any Details for knowapi_langchain-0.2.0-py3-none-any.whl

Total release size: 25.9 kB

Release files / knowapi_langchain-0.2.0.tar.gz

Download URL knowapi_langchain-0.2.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
28361837ccf013ed6e042435943db5be21170a6ef5c4851ff07c32d82c76a132
BLAKE2b-256 checksum
How to use checksums
0dd8e14a3a900fa58d2de659363f2f50f71e8d864ceabf12a683999c63a0e990
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.2

Release files / knowapi_langchain-0.2.0-py3-none-any.whl

Download URL knowapi_langchain-0.2.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c82930e2045e97aff967fb84d00ff964759782ec3e9a8af4119230f3cf034fb6
BLAKE2b-256 checksum
How to use checksums
bd6b467e54e9dde7b1be2abd10e99049a2b1e3a43392829672e8cc20f94b1fc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.2

Security for knowapi-langchain 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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