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. No membership is needed (x402 or prepaid credit pays per call); memberships (Starter, Pro, Business) add monthly allowances and the business applications: https://api.knowapi.dev/v1/plans. Ask: a new question is $0.25, asking the same question again is $0.0037 (the saved API returns the latest records). Creating a custom API is free.

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.
  • Memberships: kn.buy_membership("starter") reads the live price and revision from /v1/plans and sends them with the purchase (a changed price is refused with 409, never charged). Without api_key, one x402 payment returns a new api_key holding the membership (shown once: store it); the client uses it from then on. A membership is one payment, so set per_call_usd at or above its price. Every 402, quote and /v1/pricing lists the same URLs as the membership purchase method.

Metadata

Release files for knowapi-langchain 0.3.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.3.0
File Size Uploaded Provenance Actions
knowapi_langchain-0.3.0.tar.gz 16.0 kB Without provenance Details for knowapi_langchain-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 28.1 kB

Release files / knowapi_langchain-0.3.0.tar.gz

Download URL knowapi_langchain-0.3.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
dab2d6076deb6ae53a3e7bbdddfeaa1c63c90230de86d4c55f80f368cf9cb30a
BLAKE2b-256 checksum
How to use checksums
58bb8901fcfcabb53c1c9859838af69e82ccb2d9351b40c634f1e438610c24b8
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.3.0-py3-none-any.whl

Download URL knowapi_langchain-0.3.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5a4ec52e7769806e39d22e4248454e0545c199a73f7ca76b7cc54dc1b12f52a
BLAKE2b-256 checksum
How to use checksums
548d4be4f2274af13eb0306dc023c0a3a0406ce160e73a8ad4bd6dbc66fb371f
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.3.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