Sofya with LangChain
The langchain-sofya package gives LangChain agents four Sofya tools: web search, page and document fetch, extraction and cited research. One API key for all four.
SofyaSearch1 to 2 credits, +2 with an answerSearch the web and get page content, not just snippets. Optional short AI answer with include_answer.
SofyaFetch1 credit per URLRead up to 10 URLs as clean Markdown, including PDF, Word, Excel and PowerPoint files.
SofyaExtract10 creditsRead a page and return the information you ask for.
SofyaResearch50 creditsRun several searches, read the sources and return a report with citations.
1. Install
pip install -U langchain-sofyaIt works with langchain-core 0.3 and 1.x on Python 3.10 or newer.
2. Get an API key
Sign in at sofya.co and create a key on the dashboard. Keys look like sofya_live_.... Pay as you go from $10; GitHub accounts a year or older get free monthly credits.
export SOFYA_API_KEY=sofya_live_...Or pass api_key="sofya_live_..." to any tool.
3. Call a tool
from langchain_sofya import SofyaSearch
search = SofyaSearch(max_results=5, include_answer=True)
result = search.invoke({"query": "latest stable Python release"})
print(result["answer"])
for r in result["results"]:
print(r["title"], r["url"])Arguments set on the tool are defaults. The model can override them on each call, for example max_results, include_domains, topic or freshness.
from langchain_sofya import SofyaExtract, SofyaFetch, SofyaResearch
SofyaFetch().invoke({"urls": ["https://example.com/report.pdf"]})
SofyaExtract().invoke({
"url": "https://en.wikipedia.org/wiki/Eiffel_Tower",
"prompt": "How tall is it and when did it open?",
})
SofyaResearch(max_sources=15).invoke({"query": "How do heat pumps perform in cold climates?"})Each tool also runs async through ainvoke.
4. Give them to an agent
from langchain.agents import create_agent
from langchain_sofya import SofyaExtract, SofyaFetch, SofyaSearch
agent = create_agent(
"anthropic:claude-sonnet-5-5",
tools=[SofyaSearch(), SofyaFetch(), SofyaExtract()],
)
agent.invoke({"messages": [{"role": "user", "content": "What changed in the latest Node.js LTS?"}]})Any chat model with tool calling works. The tools also plug into LangGraph's ToolNode like any other LangChain tool.
Settings
| Argument | Environment variable | Default |
|---|---|---|
api_key | SOFYA_API_KEY | required |
base_url | SOFYA_BASE_URL | https://sofya.co |
timeout | - | 120 seconds |
Notes
- Every call uses credits from your account, the same as a REST call, and shows in your dashboard usage.
- An invalid key, an empty balance or a rate limit comes back to the model as a tool message instead of an exception, so the agent can tell the user.
- Source: github.com/sofya-co/langchain-sofya. Package: pypi.org/project/langchain-sofya.
- Clients that speak MCP can use the hosted server at
https://mcp.sofya.co/mcpinstead. See the API docs. - Questions: support@sofya.co