Run FinGPT's agent pipelines on a custom OpenAI-compatible endpoint.
Updated 2026-07-16
FinGPT's multi-agent analysis pipeline configures its LLM through an AG2 LLMConfig dict that takes api_type "openai" and a base_url. Set base_url to https://api.apisrouter.com/v1, pass one key, and the researcher, sentiment, and advisor agents can run on any model id in the catalog.
Quick answer: base_url in the AG2 LLMConfig dict.
FinGPT's multi-agent financial analysis pipeline (fingpt/ag2_financial_analysis_pipeline.ipynb in the upstream repo) builds its LLM configuration as an AG2 LLMConfig dict with four keys: model, api_key, api_type, and base_url. The upstream notebook itself points base_url at an OpenAI-compatible router endpoint rather than at api.openai.com, so routing through a gateway is the documented pattern here, not a workaround. To run the pipeline through APIsRouter, set api_type to "openai", set base_url to https://api.apisrouter.com/v1, put your gateway key in api_key, and set model to any catalog id. Every AssistantAgent in the notebook receives the same llm_config object, so one dict moves the whole agent team.
from autogen import LLMConfig # ag2[openai]>=0.11.4
llm_config = LLMConfig({
"model": "claude-sonnet-4-6",
"api_key": os.environ["APISROUTER_API_KEY"],
"api_type": "openai",
"base_url": "https://api.apisrouter.com/v1",
})Where FinGPT actually calls an LLM API.
FinGPT (AI4Finance-Foundation on GitHub, roughly 21K stars) is two things under one name, and knowing which half you are running decides whether a custom endpoint matters at all. The first half is fine-tuned open weights: the LoRA training notebooks for Llama and ChatGLM that made the project known. Those run locally or on rented GPUs through Hugging Face transformers, make no chat-completions calls, and no base URL applies to them. The second half is the application pipelines, and this is where the OpenAI-compatible surface lives. The AG2 multi-agent analysis pipeline wires three AssistantAgents (a news researcher, a sentiment analyst, and an investment advisor) to one LLMConfig, augments them with yfinance tool calls and a local FinBERT sentiment classifier, and lets them pass an equity analysis between roles. The financial report analysis pipeline (fingpt/FinGPT_FinancialReportAnalysis) drives LangChain's ChatOpenAI against SEC filings pulled through sec-api and Financial Modeling Prep. Both pipelines send standard /v1/chat/completions requests, both expose the endpoint as a parameter, and both forward the model field as a plain string, which is what lets a Claude or DeepSeek id ride on an "openai" api_type once the endpoint behind base_url serves it.
Full setup: the AG2 pipeline and the report-analysis pipeline.
The AG2 pipeline is the cleanest integration. Replace the notebook's LLMConfig values with the gateway endpoint and your preferred model id, and the three agents plus their tool-calling loop run unchanged. The financial-data side (yfinance quotes, FinBERT sentiment scoring) is local and free of API keys, so the LLM endpoint is the only external dependency you are moving. The report-analysis pipeline uses LangChain's ChatOpenAI, which accepts api_key and base_url as constructor arguments; the upstream notebook demonstrates exactly this pair when it shows how to swap in a local OpenAI-compatible server. Point the same two arguments at the gateway instead. Note that this notebook also wants SEC and Financial Modeling Prep credentials for its data pulls; those are market-data keys, unrelated to the LLM endpoint, and they stay as they are.
import os
from autogen import AssistantAgent, LLMConfig
llm_config = LLMConfig({
"model": "claude-sonnet-4-6", # any catalog id
"api_key": os.environ["APISROUTER_API_KEY"],
"api_type": "openai",
"base_url": "https://api.apisrouter.com/v1",
})
researcher = AssistantAgent(name="News_Researcher", llm_config=llm_config)
analyst = AssistantAgent(name="Sentiment_Analyst", llm_config=llm_config)
advisor = AssistantAgent(name="Investment_Advisor", llm_config=llm_config)Choosing models for financial analysis agents.
Because every candidate is one model string against the same endpoint, the practical loop is to fix your tickers and dates, run the pipeline once per candidate id, and diff the advisor output. The per-key usage log prices each candidate run for you, which settles the quality-per-token argument with numbers instead of instinct.
- The advisor role is the reasoning bottleneck. It synthesizes the researcher's findings, the sentiment scores, and the risk picture into an outlook, and a frontier reasoning model (claude-opus-4-7, gpt-5.5) is where that synthesis stops being generic.
- The researcher and analyst roles are volume roles: reading headlines, structuring tool output, scoring drafts. claude-sonnet-4-6 or deepseek-v4-pro keeps them sharp without frontier pricing on every intermediate turn.
- Report analysis is a long-context workload. A 10-K section plus price-target context is a large prompt, so test gemini-3.1-pro-preview or claude-sonnet-4-6 on the filing side before assuming the default.
- FinGPT's roots are bilingual. If your pipeline reads Chinese-language filings or news, glm-5.2 and deepseek-v4-pro are natively strong there and addressable through the same endpoint by id.
- Running one LLMConfig for all agents is the notebook default, but nothing stops you from building two dicts against the same base_url, a frontier one for the advisor and a fast one for the readers, and assigning them per agent.
Pay-as-you-go · transparent per-model pricing
Selected models are priced below official list prices. Exact input, output, cache, and per-request prices are shown for each model.
| Model | Official Price | Our Price |
|---|---|---|
| Claude Opus 4.7 | $5.00 / $25.00 per M | $4.00 / $20.00 per M |
| Claude Sonnet 4.6 | $3.00 / $15.00 per M | $2.40 / $12.00 per M |
| GPT-5.5 | $5.00 / $30.00 per M | $4.00 / $24.00 per M |
| DeepSeek V4 Pro | $0.43 / $0.87 per M | $0.39 / $0.78 per M |
| GLM-5.2 | $1.14 / $4.00 per M | $1.03 / $3.60 per M |
Caveats: not every base_url in FinGPT is the LLM.
FinGPT is a research monorepo, and a few things look like LLM endpoint settings without being them. The Forecaster's market_sentiment.py has api_key and base_url parameters, but they configure a market-data sentiment service (read from ADANOS_API_KEY), not a chat-completions endpoint. Changing that base_url does not route any LLM traffic. The FinGPT-Forecaster models themselves are fine-tuned Llama weights served through Hugging Face, so the forecaster demo is not an OpenAI-compatible consumer at all. The newer Finogrid platform inside the repo selects its LLM through a FINGPT_LLM_PROVIDER environment variable (openai, minimax, or fingpt) and reads OPENAI_API_KEY for the openai provider. As of July 2026 its example environment file documents the provider switch and the key, but no base-URL override variable, so treat Finogrid as out of scope for a gateway until upstream documents one. Finally, the AG2 notebook pins ag2[openai] at 0.11.4 or newer. Older pyautogen 0.2-era installs configure the same four keys through config_list entries instead of the LLMConfig class; the keys are identical, so the routing works, but match your import style to the AutoGen generation you actually have installed.
Who routes FinGPT through a gateway.
- Quant researchers running the multi-agent analysis across a ticker list. Dozens of agent turns per equity make per-key usage visibility more useful than a vendor dashboard per provider.
- Teams comparing analysis quality across model families. Each candidate is one model string in LLMConfig, not a new provider integration and account.
- Analysts processing filings in bulk through the report pipeline, where long-context pricing differences between ids dominate the bill.
- Bilingual finance teams pairing Chinese-strong ids like glm-5.2 or deepseek-v4-pro with Claude or GPT reasoning, all behind one endpoint.
- Developers without access to a given vendor's billing. Top-up based access with no card requirement removes the per-provider sign-up dependency.
Verify the endpoint and debug the first run.
Before launching the notebook, list the models your key can address; the model string in LLMConfig must match a served id exactly. First-run failures follow a short list. A 401 means the api_key in the dict is not a valid key for the endpoint in base_url; because both live in the same dict, print the dict (minus the key) and check you edited the copy the agents actually received. A model-not-found error is an id typo, and the /v1/models output is the authoritative spelling. A connection error usually means base_url lost its /v1 suffix, since the client appends /chat/completions to whatever base you give it. And if the sentiment step fails while agent chat works, that is the local FinBERT classifier or a missing transformers install, not the gateway. Once requests flow, the APIsRouter console shows per-request model, token counts, and spend. Multi-agent pipelines multiply calls quickly, and the usage view is how you see which agent role is consuming the tokens before you scale the run to a full watchlist.
curl -s https://api.apisrouter.com/v1/models \
-H "Authorization: Bearer $APISROUTER_API_KEY" | head -50FAQ
Does FinGPT support a custom OpenAI-compatible endpoint out of the box?
Yes, in its API-driven pipelines. The AG2 multi-agent analysis notebook configures LLMConfig with api_type "openai" plus a base_url, and the report-analysis notebook passes base_url to LangChain's ChatOpenAI. Both are upstream patterns; the fine-tuned local models are a separate, offline half of the project.
Can the FinGPT agents run on Claude or DeepSeek models this way?
Yes. The api_type stays "openai" and the model field is forwarded as a plain string over /v1/chat/completions. Any id served by the endpoint behind base_url works, including Claude, DeepSeek, GLM, and Gemini ids.
Do I still need an OpenAI account for the AG2 pipeline?
No. With base_url pointing at the gateway and api_key holding a gateway key, no request touches OpenAI hosts. The upstream notebook itself demonstrates this by routing through a non-OpenAI compatible endpoint.
Does a custom base_url affect FinGPT's market data or FinBERT sentiment scoring?
No. yfinance quotes and the FinBERT classifier run locally without API keys, and the report pipeline's SEC and Financial Modeling Prep credentials are separate data keys. The LLM endpoint is the only thing base_url moves.
What about the base_url parameter in the Forecaster's market_sentiment.py?
That one configures a market-data sentiment service authenticated by ADANOS_API_KEY, not an LLM endpoint. The Forecaster's own models are fine-tuned weights served through Hugging Face, so no OpenAI-compatible routing applies there.
Does the Finogrid platform inside FinGPT support a custom endpoint too?
Not documented as of July 2026. Finogrid selects a provider via FINGPT_LLM_PROVIDER and reads OPENAI_API_KEY, but its example environment file shows no base-URL override, so assume direct vendor routing there until upstream adds one.