Install SEC API in Vercel AI SDK
Use@ai-sdk/mcp to register SEC API as a streamable HTTP MCP server with an x-api-key header. The returned tools can be passed to your AI SDK model call.
Prerequisites
- SEC API key. Sign up at secapi.ai. Set
SECAPI_API_KEY. - Node.js plus
ai,@ai-sdk/mcp, and a model provider package.
Install
Verify
Run the snippet. The agent should call thefilings.latest tool with ticker: AAPL, form: 8-K and print the filing URL plus a short summary.
Troubleshooting
401 Unauthorized—x-api-keyis missing or wrong. Sanity check:curl https://api.secapi.ai/v1/limits -H "x-api-key: $SECAPI_API_KEY".429 Too Many Requests— rate limit hit. SeeGET https://api.secapi.ai/v1/billingfor your plan’s cap.- Process hangs after first call — always
await mcp.close()in afinallyblock (or inonFinishandonErrorif you use streaming). Open SSE connections will keep the event loop alive. Cannot find module '@ai-sdk/mcp'— install the MCP package or check your AI SDK version’s MCP client import path.
Streaming variant
ForstreamText, close the client in both callbacks:
Next
- Available tools — SEC + market data tools
- Give this prompt to your agent — canonical agent briefing for richer workflows