SEC EDGAR API for AI agents: function calling for financial data
Ask an AI agent for Apple's exact revenue last year. It will give you a number, fast and confident. Sometimes it is even right.
That "sometimes" is the whole problem.
Here is how to make an agent pull real SEC financials instead of guessing them, using function calling or MCP.
AI agents hallucinate financial figures because they answer from training data, not a live source. Function calling fixes it: you give the agent a tool that fetches real SEC numbers on demand. With the SEC EDGAR API you either write a tool schema over the REST endpoints or point an MCP client at Edgrapi's hosted server. Either way, the model stops guessing and starts citing.
Why do AI agents get financial numbers wrong?
Because a language model predicts text; it does not look anything up. Ask for a revenue figure and it generates the most likely-looking number from training data, which may be months stale or simply invented. Work on financial tasks shows models stay strong on simple lookups but can fall toward zero accuracy on multivariate questions, per reporting on financial hallucination.
You cannot prompt your way out of this.
No amount of "be accurate" in the system prompt gives the model data it does not have. The fix is to hand it the data at question time, which is exactly what tool use does. Grounding a model in a real source cuts hallucination sharply, per research on LLM grounding.
What is function calling?
Function calling lets a model ask your code to run a function and use the result. You hand the model a list of tools, each with a name, a description, and a JSON input schema. The model decides when to call one and with what arguments, your code runs it, and the output goes back so the answer is built on real data, per Anthropic's tool use docs.
One mental model clears up most confusion.
The model never calls the API itself. It only emits a structured request that says "run get_fundamentals with ticker AAPL." Your code makes the real HTTP call and passes the result back. A setting called tool_choice controls whether the model may call tools, must call one, or must call a specific one.
How do you give an agent SEC data with function calling?
You define one tool per thing you want the agent to fetch, then point its handler at an Edgrapi endpoint. A get_fundamentals tool takes a ticker, and its handler calls /v1/fundamentals with your Bearer key. The model asks for the tool, your code runs the request, and you return the JSON as the tool result.
Here is the tool and its handler in Python:
import anthropic, requests
tools = [{
"name": "get_fundamentals",
"description": "Company income statement, balance sheet, and cash flow from SEC EDGAR, by ticker.",
"input_schema": {
"type": "object",
"properties": {"ticker": {"type": "string"}},
"required": ["ticker"],
},
}]
def get_fundamentals(ticker):
r = requests.get(
f"https://api.edgrapi.com/v1/fundamentals/{ticker}",
headers={"Authorization": "Bearer edgr_your_key"},
)
return r.json()
Pass tools to the model, and when it returns a tool call, run the matching handler and send the JSON back as the tool result.
The same idea works with the OpenAI SDK; only the field names change. Define the tool once per provider, or reach for the shortcut below. The SEC EDGAR API key guide covers the Bearer header your handler needs.
What about MCP? The shortcut.
MCP skips the glue code. The Model Context Protocol is an open standard for exposing tools behind a server, and Edgrapi runs a hosted one at api.edgrapi.com/mcp with four tools. Point an MCP client like Claude or Cursor at the URL, authenticate, and get_fundamentals, get_ratios, get_company, and get_filings appear with nothing to write.
MCP is not a bet on a niche idea.
Anthropic released it in late 2024, OpenAI adopted it across its products in 2025, and server downloads went from about 100,000 to more than 8 million in the same stretch, per the Model Context Protocol overview. If your client speaks MCP, this is the fastest path to grounded financials.
What can the agent actually do?
Anything you can phrase as a question about a company's numbers or filings. "Compare AAPL and MSFT net margin" triggers two get_ratios calls. "Link me TSLA's latest 10-K" triggers get_filings. "Is NVDA profitable" triggers get_fundamentals. The agent picks the tools, and every answer is built on data pulled at query time.
The payoff is trust.
When a research agent cites a margin, you can trace it to a filing instead of hoping the model remembered right. That is the difference between a demo and something you would let near a real decision.
Function calling or MCP: which should you use?
Use MCP if your client speaks it and you want zero setup. Use raw function calling if you need full control or you are building inside your own agent loop. Both hit the same endpoints and return the same data; the only real difference is who writes the tool layer.
| Function calling | Edgrapi MCP server | |
|---|---|---|
| Setup | You write schemas and handlers | Point a client at one URL |
| Control | Full | Four ready-made tools |
| Works with | OpenAI, Claude SDKs, custom loops | Any MCP client (Claude, Cursor) |
| Auth | Bearer key in your handler | Bearer key in the client |
| Best for | Custom agents | Fast wiring in a chat client |
Most teams start with MCP to prove the idea in a chat client, then move to function calling when they build their own agent. The main SEC EDGAR API guide covers the endpoints behind both.
Start: give your agent one tool
Pick your path. In a chat client, add the Edgrapi MCP server and ask it to compare two companies' margins. In your own code, define a single get_fundamentals tool and watch the model call it.
Grab a free Edgrapi key first; the free tier is 100 requests with no card, enough to wire up an agent and see it pull real numbers. Point it at https://api.edgrapi.com and give your agent something true to say.
Frequently asked questions
Why do AI agents hallucinate financial data?
Because a plain language model answers from patterns in its training data, not from a live source. Ask for an exact revenue figure and it produces a plausible number that may be stale or wrong. Research shows top models stay accurate on simple lookups but can collapse toward zero on multivariate financial questions. Function calling fixes this by letting the agent fetch the real number from the SEC EDGAR API.
What is function calling in an LLM?
Function calling, also called tool use, lets a model ask your code to run a defined function and hand back the result. You describe each tool with a name, a description, and a JSON input schema. The model decides when to call it, your code executes the call, and the result is fed back so the model answers from real data instead of memory.
How do I give an AI agent access to the SEC EDGAR API?
Two ways. Define a tool schema like get_fundamentals with a ticker input, and write a handler that calls the Edgrapi REST endpoint and returns the JSON. Or skip the glue code and point an MCP client at Edgrapi's hosted server at api.edgrapi.com/mcp, which exposes four ready-made tools. Both give the agent real SEC financials; MCP is faster to wire up.
What is the difference between function calling and MCP?
Function calling is the model feature: the LLM emits a structured request to run a tool you defined. MCP, the Model Context Protocol, is an open standard for packaging those tools behind a server so any compatible client can use them without custom code. Anthropic released MCP in 2024 and OpenAI adopted it in 2025. Edgrapi supports both.
Does Edgrapi have an MCP server?
Yes. Edgrapi runs a hosted MCP server at api.edgrapi.com/mcp with four tools: get_fundamentals, get_ratios, get_company, and get_filings. Point an MCP client like Claude or Cursor at the URL, authenticate with your Bearer key, and the tools register automatically. The free tier is 100 requests with no credit card, so you can test an agent before paying.
Which AI models support tool use for financial data?
Any model with function calling, which includes the current OpenAI and Anthropic Claude models, plus Gemini and most agent frameworks. They all take tool definitions as JSON schemas and return structured tool calls. So the same Edgrapi tools work across providers: define them once, or use the MCP server, and the agent pulls real SEC data whichever model you run.