TradingAgents को एक custom OpenAI-compatible backend पर चलाएं।

Updated 2026-07-30

TradingAgents एक openai_compatible provider mode के साथ ship होता है। backend_url को https://api.apisrouter.com/v1 set करें, एक key export करें, और deep-think और quick-think दोनों agents एक ही endpoint से route होते हैं, हर catalog model id से addressable।

Quick answer: तीन settings TradingAgents को कहीं भी route करती हैं।

TradingAgents custom endpoints को natively support करता है। llm_provider को "openai_compatible" set करें, backend_url को अपने endpoint address पर set करें, और उस endpoint के लिए एक key के साथ OPENAI_COMPATIBLE_API_KEY export करें। APIsRouter के साथ backend URL https://api.apisrouter.com/v1 है, और catalog का हर model deep_think_llm और quick_think_llm slots से इसकी exact model id द्वारा addressable बन जाता है। यह upstream repo में एक documented configuration path है, कोई fork या patch नहीं। Same values environment variables के तौर पर भी दी जा सकती हैं (TRADINGAGENTS_LLM_PROVIDER, TRADINGAGENTS_LLM_BACKEND_URL, TRADINGAGENTS_DEEP_THINK_LLM, TRADINGAGENTS_QUICK_THINK_LLM), तो एक scheduled job या CI runner बिना Python code छुए backends switch कर सकता है।

config["llm_provider"] = "openai_compatible"
config["backend_url"] = "https://api.apisrouter.com/v1"
# auth: export OPENAI_COMPATIBLE_API_KEY=sk-...

TradingAgents अपने LLM backend से कैसे बात करता है।

TradingAgents (GitHub पर TauricResearch, 93K+ stars) एक multi-agent trading framework है। एक analysis run fundamentals, sentiment, news, और technicals कवर करने वाली एक analyst team के across fan out होता है, फिर एक bull researcher और एक bear researcher एक या ज़्यादा debate rounds में case पर बहस करते हैं, एक trader agent position propose करता है, और final decision से पहले एक risk-management layer इसे review करती है। Framework उस काम को दो model slots में बांटता है। deep_think_llm reasoning-heavy steps handle करता है: research debate, trader decision, और risk review। quick_think_llm high-volume steps handle करता है: data पढ़ना, news summarize करना, और analyst reports draft करना। दोनों slots standard /v1/chat/completions requests issue करते हैं। Provider setting सिर्फ तय करती है कि वे requests किस client और host पर जाती हैं, और openai_compatible इन्हें आपके configure किए backend_url पर भेजता है। Natively, TradingAgents OpenAI, Anthropic, Google, और DeepSeek को भी first-party providers के तौर पर support करता है, लेकिन हर एक को अपना account, अपनी key, और per run एक provider चाहिए। openai_compatible mode इसे collapse कर देता है: TradingAgents model field को एक plain string के तौर पर pass through करता है, तो जब backend_url के पीछे का endpoint कई vendors serve करता है, एक Claude deep-think slot और एक GPT या DeepSeek quick-think slot same analysis में चल सकते हैं। वह per-role mixing framework को एक single vendor endpoint की बजाय एक gateway से route करने की practical वजह है।

पूरा setup: Python config या environment variables।

Programmatic path DEFAULT_CONFIG copy करता है और चार keys override करता है। जो key custom endpoint के against authenticate करती है वह OPENAI_COMPATIBLE_API_KEY से पढ़ी जाती है, तो इसे config dict या source file में कभी दिखना नहीं पड़ता। Environment-variable path default_config.py में _ENV_OVERRIDES mapping के through same values set करता है और Python API और interactive CLI (tradingagents, या python -m cli.main) दोनों के लिए काम करता है। ध्यान दें कि backend_url default में None है, जिस case में हर provider का client अपने खुद के default endpoint पर fall back करता है; override तभी effect में आता है जब आप इसे explicitly set करें। Market data एक अलग concern है। TradingAgents अपने data vendors (उदाहरण के लिए ALPHA_VANTAGE_API_KEY) के through quotes और fundamentals खींचता है, और वे credentials LLM endpoint से unrelated हैं। backend_url बदलना data pipeline को नहीं छूता।

from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG

config = DEFAULT_CONFIG.copy()
config["llm_provider"] = "openai_compatible"
config["backend_url"] = "https://api.apisrouter.com/v1"
config["deep_think_llm"] = "claude-opus-4-7"    # debate rounds + trade decision
config["quick_think_llm"] = "claude-sonnet-4-6" # analysts, summaries
config["max_debate_rounds"] = 2

ta = TradingAgentsGraph(debug=True, config=config)
_, decision = ta.propagate("NVDA", "2026-07-15")
print(decision)

deep-think और quick-think models चुनना।

Upstream default deep slot में एक frontier model को quick slot में एक mini model के साथ pair करता है, जो सही shape है: reasoning capacity वहां खर्च करें जहां decision बनता है, और volume capacity वहां जहां reading होती है। एक endpoint के through routing pairing को runs के बीच एक two-line change बना देती है, तो practical workflow deep slot को fixed रखना और quick slot को अपने backtest metrics के against A/B करना है, guess करने की बजाय।

  • deep_think_llm bull/bear debate, trader decision, और risk review carry करता है। Per run कम calls, पर हर एक पूरे analyst context पर reason करती है, और max_debate_rounds इन्हें multiply करती है। यहीं एक frontier reasoning model (claude-opus-4-7, gpt-5.5) अपने tokens earn करती है।
  • quick_think_llm हर analyst step पर fire होता है: fundamentals पढ़ना, sentiment score करना, news summarize करना, reports draft करना। किसी run का ज़्यादातर request volume यहीं आता है, तो एक fast mid-tier model (claude-sonnet-4-6, deepseek-v4-pro) debate inputs को degrade किए बिना runs को fast रखती है।
  • Long-context loads, जैसे analysts में पूरी filings या बड़े news windows feed करना, वह जगह है जहां gemini-3.1-pro-preview quick slot में test करने लायक है।
  • Backtests हर चीज़ को amplify करते हैं। 50 tickers और 20 dates का एक sweep 1,000 propagate() calls है, तो एक quick-think model choice जो एक run पर marginal दिखती है वह sweep scale पर token bill को dominate करती है।

जितना उपयोग उतना भुगतान · आधिकारिक मूल्य से कम

Selected models are priced below official list prices. Exact input, output, cache, and per-request prices are shown for each model.

मॉडलआधिकारिक मूल्यहमारा मूल्य
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
Gemini 3.1 Pro Preview$2.00 / $12.00 per M$1.60 / $9.60 per M
DeepSeek V4 Pro$0.43 / $0.87 per M$0.40 / $0.90 per M

Sweep scale पर backtesting: keys, pinning, और limits।

एक बार single-run setup काम करे, failure surface sweep की तरफ shift हो जाती है। तीन habits एक multi-day backtest को reproducible और debuggable रखती हैं। Exact model ids pin करें। कुछ vendors पर bare model names rolling pointers हैं जो चुपचाप नए snapshots पर move हो जाती हैं, जिसका मतलब है Monday को शुरू हुआ और Friday को ख़त्म हुआ एक backtest ने शायद एक ही model नहीं चलाया हो। जहां catalog एक dated variant list करता है, config में dated id डालें, और config dict को results के बगल में record करें जैसे आप एक random seed record करते हैं। Per experiment एक key इस्तेमाल करें। Keys बनाने में free हैं, और एक key को एक sweep तक scope करना usage log को experiment के cost ledger में बदल देता है: token counts और spend per model, exactly उस sweep की runs तक filterable। जब दो experiments एक key share करते हैं, बाद में spend attribute करना timestamps grep करना मतलब रखता है। Parallelize करने से पहले अपनी concurrency ceiling जानें। propagate() per ticker-date synchronous है, तो sweeps आमतौर पर processes के across shard होते हैं। हर shard पहले quick-think slot पर request rate multiply करता है, और debate के बीच एक 429 पूरी run की कीमत लेता है, एक request की नहीं। Cold पचास workers launch करने की बजाय console देखते हुए shard count ramp करें; pooled upstream channels ceiling बढ़ाते हैं पर इसे infinite नहीं बनाते।

कौन TradingAgents को एक gateway के through route करता है।

  • Backtesters जो ticker-by-date sweeps चलाते हैं। Per experiment सैकड़ों propagate() calls per-key usage visibility और एक single billing surface को चार vendor dashboards से ज़्यादा useful बना देती हैं।
  • Researchers जो model pairs compare करते हैं। deep_think_llm को Claude, GPT, और DeepSeek ids के बीच swap करना एक endpoint के against एक config edit है, per candidate एक नया vendor account नहीं।
  • Teams जो per role vendors mix करती हैं। Debate के लिए Claude, analyst volume के लिए DeepSeek। Native provider mode एक run को एक vendor पर lock करता है; एक multi-vendor endpoint नहीं करता।
  • Developers जिनके पास किसी given vendor की billing तक access नहीं है। बिना card requirement वाला top-up based access per-provider sign-up dependency हटा देता है।
  • Scheduled और CI runs। Env-only setup का मतलब है runner image को per provider एक की बजाय एक secret (OPENAI_COMPATIBLE_API_KEY) चाहिए।

Endpoint verify करें और पहली run को debug करें।

एक पूरी analysis चलाने से पहले, confirm करें endpoint उन models के साथ जवाब देता है जिन्हें आप इस्तेमाल करने की योजना बना रहे हैं। अपनी key के साथ /v1/models के against एक one-line curl हर addressable id list करता है; deep_think_llm और quick_think_llm में strings exactly उन ids से match होनी चाहिए। पहली run पर failure modes consistent हैं। एक 401 का मतलब लगभग हमेशा है OPENAI_COMPATIBLE_API_KEY एक अलग shell में export हुई जहां tradingagents नहीं चला, या बिल्कुल export नहीं हुई; .bashrc में set किए env vars एक systemd unit या cron job तक नहीं पहुंचते जब तक unit file खुद इन्हें export ना करे। एक model-not-found error का मतलब है id string catalog से match नहीं करती: ids exact हैं, version suffixes शामिल, और ऊपर वाला /v1/models output source of truth है। backend_url set होने पर एक connection error का मतलब आमतौर पर है URL से इसका /v1 suffix छूट गया, क्योंकि client आपके दिए base में /chat/completions जैसे route paths append करता है। अगर run काम करती है पर debate phase में stall होती दिखे, तो यह लंबे contexts वाले reasoning models के लिए normal latency है, endpoint problem नहीं; agent steps stream होते देखने के लिए debug=True on रखें। बहुत लंबे deep-think turns पर genuine timeouts एक client-side setting हैं, और यह conclude करने से पहले कि backend ने request drop की इसे बढ़ाना worth है। एक बार requests flow करने लगें, APIsRouter console per-request model, token counts, और spend दिखाता है, जो इतने call-heavy framework के लिए यह देखने का सबसे तेज़ तरीका है कि एक run के tokens exactly कहां जाते हैं।

curl -s https://api.apisrouter.com/v1/models \
  -H "Authorization: Bearer $OPENAI_COMPATIBLE_API_KEY" | head -50

अक्सर पूछे जाने वाले प्रश्न

क्या TradingAgents एक openai_compatible endpoint के through Claude और Gemini models support करता है?

हां। openai_compatible mode में framework /v1/chat/completions पर backend_url को model field एक plain string के तौर पर भेजता है। Endpoint जो भी id serve करता है वह काम करती है, Claude, Gemini, और DeepSeek ids शामिल, deep-think या quick-think दोनों में से किसी slot में।

TradingAgents एक custom backend_url के साथ कौन सी API key इस्तेमाल करता है?

OPENAI_COMPATIBLE_API_KEY। openai_compatible provider इसे environment से पढ़ता है, तो key कभी आपके config dict या source files में नहीं दिखती। OPENAI_API_KEY सिर्फ native openai provider इस्तेमाल करता है।

क्या same run में deep_think_llm और quick_think_llm अलग-अलग vendors से आ सकते हैं?

एक multi-vendor endpoint के through, हां: दोनों slots same backend_url को post करते हैं और model string per request vendor तय करती है। Native providers (openai, anthropic, google, deepseek) के साथ एक run दोनों slots के लिए एक vendor पर lock हो जाती है।

backend_url set होने के बाद भी क्या मुझे OpenAI account चाहिए?

नहीं। llm_provider को openai_compatible set होने पर, कोई request OpenAI hosts को नहीं जाती और OPENAI_API_KEY पढ़ा नहीं जाता। आपको अब भी वे market-data credentials चाहिए जो TradingAgents इस्तेमाल करता है (उदाहरण के लिए ALPHA_VANTAGE_API_KEY), जो LLM endpoint से independent हैं।

क्या interactive CLI भी custom endpoint honor करता है?

हां। CLI (tradingagents, या python -m cli.main) same config resolve करता है, और TRADINGAGENTS_LLM_PROVIDER / TRADINGAGENTS_LLM_BACKEND_URL environment variables provider prompt से पहले इसे override करते हैं, तो scheduled या containerized CLI runs को routing के लिए कोई interactive input नहीं चाहिए।

एक TradingAgents analysis कितने tokens consume करती है?

यह max_debate_rounds, analysts की संख्या, और वे कितना market context ingest करते हैं इसके साथ vary करती है; एक single ticker-date analysis आमतौर पर सैकड़ों हज़ार tokens में पहुंचती है, ज़्यादातर quick-think slot पर। APIsRouter console में per-key usage view per run exact split दिखाता है, जो estimate करने से ज़्यादा reliable है।