अपना Khoj second brain एक custom OpenAI base URL पर चलाएं।

Updated 2026-07-29

Khoj दो surfaces वाला एक OpenAI-proxy setup document करता है: एक OPENAI_BASE_URL environment variable जो पहली run पर models seed करता है, और admin panel में एक Api Base Url field वाली एक AI Model API entry। दोनों में से किसी को https://api.apisrouter.com/v1 पर point करें और chat, agents, और automations किसी भी catalog model पर चलते हैं।

Quick answer: पहली run पर env var, कभी भी admin panel।

Khoj की self-hosting compose file में एक commented OPENAI_BASE_URL line है जो, इसके अपने शब्दों में, दूसरे OpenAI API compatible providers के लिए intended है। पहली startup से पहले इसे https://api.apisrouter.com/v1 set करें और OPENAI_API_KEY में एक gateway key रखें, और Khoj की initialization कुछ असामान्य रूप से helpful करती है: यह endpoint की model list query करती है और अपनी chat-model table को endpoint जो भी id serve करता है उससे seed करती है, तो catalog बिना manual entry के Khoj के model picker में दिखता है। पहले से initialized server पर, इसकी बजाय admin panel इस्तेमाल करें। एक AI Model API entry बनाएं (fields: Name, Api Key, Api Base Url) जो gateway पर point करे, फिर Chat Model entries बनाएं जिनका Name exact model id हो, Model Type Openai set हो, और उस AI Model API से linked हो। दोनों surfaces docs.khoj.dev पर Khoj की OpenAI-proxy guide में documented हैं।

services:
  server:
    environment:
      - OPENAI_BASE_URL=https://api.apisrouter.com/v1
      - OPENAI_API_KEY=sk-YOUR-APISROUTER-KEY

Khoj अपने chat model से क्या करता है।

Khoj (GitHub पर khoj-ai, लगभग 36K stars) एक self-hostable AI second brain है: यह आपके notes और documents (markdown, org-mode, PDFs, और बहुत कुछ) index करता है, फिर आपको उन पर chat करने देता है, अपनी personas और tools वाले custom agents चलाने देता है, एक cron पर fire होने वाले automations schedule करने देता है, और multi-step research runs launch करने देता है। एक hosted app भी है, लेकिन self-hosted server वह जगह है जहां custom endpoints apply होते हैं, और यह वही deployment है जिसे यह page describe करता है। उन features में से हर एक जो chat model आप select करते हैं उससे होकर गुज़रता है। Document chat retrieved note chunks को prompt में pack करता है, agents tool calls और persona instructions add करते हैं, automations same pipeline को unattended चलाते हैं, और research mode प्रति सवाल कई model calls chain करता है। Model Type Openai Khoj को बताता है कि linked AI Model API entry के Api Base Url से /v1/chat/completions बोले, model Name को एक plain string के तौर पर forward करते हुए, यही वजह है कि एक Claude या DeepSeek id वहां काम करती है जब तक endpoint उसे serve करता है। Search embeddings एक अलग subsystem हैं। Khoj default रूप से आपके documents को एक local sentence-transformers model से embed करता है, तो indexing और semantic search इस बात की परवाह किए बिना काम करते रहते हैं कि आप chat endpoint के साथ क्या करते हैं। Chat को gateway के through route करना सिर्फ reasoning bill move करता है।

पूरा setup: admin panel entries step by step।

एक running server पर, पूरा integration तीन admin screens है। पहले, AI Model API add करें: /server/admin/database/aimodelapi/add खोलें, इसे नाम दें, gateway key को Api Key में paste करें, और Api Base Url को https://api.apisrouter.com/v1 set करें। दूसरे, chat models add करें: /server/admin/database/chatmodel/add पर, Name को एक exact catalog id set करें (claude-sonnet-4-6, deepseek-v4-flash), Model Type को Openai set करें, अभी बनाई गई Ai Model Api entry link करें, और Max prompt size को model की context window के फिट होने वाली value set करें। Docs सलाह देते हैं कि OpenAI-type models के लिए Tokenizer unset छोड़ें। Picker में चाहिए हर model के लिए repeat करें। तीसरे, model select करें: /settings पर, अपना नया chat model default के तौर पर चुनें। Agents per agent model override कर सकते हैं, यही तरीका है जिससे एक Khoj instance daily automations के लिए एक fast id और research के लिए एक frontier id चलाता है।

1) /server/admin/database/aimodelapi/add
   Name:         APIsRouter
   Api Key:      sk-YOUR-APISROUTER-KEY
   Api Base Url: https://api.apisrouter.com/v1

2) /server/admin/database/chatmodel/add
   Name:         claude-sonnet-4-6   (exact catalog id)
   Model Type:   Openai
   Ai Model Api: APIsRouter
   Max prompt size: 100000

3) /settings -> select the new chat model

Second brain के लिए models चुनना।

चूंकि chat models एक AI Model API के against add की गई rows हैं, picker में दो या तीन ids रखना कुछ खर्च नहीं करता। Practical setup एक fast default plus एक frontier escalation है, दोनों same key से billed ताकि usage log दिखाए कि हर tier आपके notes पर actually कितना खर्च करता है।

  • Document chat input-heavy है: retrieved note chunks answer से कहीं बड़े होते हैं। Per-input-token price प्रति सवाल cost drive करती है, जो everyday recall के लिए claude-haiku-4-5-20251001, deepseek-v4-flash, या gemini-3.5-flash को favour करती है।
  • Research mode calls multiply करता है। एक research सवाल कई model turns chain कर सकता है, तो वहां assign की गई id किसी भी दूसरी setting से ज़्यादा bill move करती है; claude-sonnet-4-6 balanced pick है, gpt-5.4 escalation।
  • Scheduled automations unattended चलते हैं। इन्हें एक subscription की तरह price करें: प्रति दिन calls गुणा प्रति call tokens, जो exactly वही है जो per-key usage log report करता है।
  • Personal knowledge contradiction-rich है (plans बदलते हैं, notes stale हो जाते हैं), और models इसमें अलग होते हैं कि वे conflicting notes को blend करने की बजाय कितनी अच्छी तरह flag करते हैं; commit करने से पहले same question set पर दो ids test करें।
  • Khoj में Max prompt size per chat model है, तो एक long-context id तभी pay off करती है जब उस field को match करने के लिए raise किया जाए।

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

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

मॉडलआधिकारिक मूल्यहमारा मूल्य
Claude Sonnet 4.6$3.00 / $15.00 per M$2.40 / $12.00 per M
Claude Haiku 4.5 20251001$1.00 / $5.00 per M$0.80 / $4.00 per M
GPT-5.4$2.50 / $15.00 per M$2.00 / $12.00 per M
DeepSeek V4 Flash$0.14 / $0.28 per M$0.10 / $0.30 per M
Gemini 3.5 Flash$1.50 / $9.00 per M$1.20 / $7.20 per M

Khoj के लिए specific failure modes।

Env var एक first-run seed है, live setting नहीं। OPENAI_BASE_URL provider entry बनाने और models discover करने के लिए initialization के दौरान पढ़ी जाती है; पहले से initialized server पर, compose file edit करने से कुछ भी visible नहीं बदलता। पहली boot के बाद बदलावों के लिए admin panel इस्तेमाल करें, या अगर genuinely एक fresh seed चाहिए तो database reset करें। Placeholder-key trap: जब OPENAI_BASE_URL बिना OPENAI_API_KEY के set होता है, Khoj key को एक placeholder से भरता है ताकि Ollama जैसे local servers काम करें। एक gateway को असली key चाहिए, तो अगर बिना key के first-run seeding हुई, chats authentication errors के साथ fail होते हैं जब तक आप admin panel में AI Model API entry में key paste नहीं करते। Auto-discovery सब कुछ seed करता है। चूंकि initialization endpoint serve करने वाला हर model list करती है, एक multi-vendor gateway एक लंबी model table seed कर सकता है। Harmless, लेकिन admin panel में prune करने लायक ताकि picker usable रहे। Chat model Name exact है। Khoj इसे verbatim forward करता है; एक typo पहले message पर model-not-found के तौर पर सामने आती है, और gateway का /v1/models output authoritative spelling है। और अगर आपके notes पर semantic search misbehave करे, वह local embedding subsystem है, chat endpoint से unrelated।

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

  • Self-hosters जो per model family vendor account के बिना अपने notes पर frontier-model chat चाहते हैं; एक key Claude, GPT, DeepSeek, और Gemini ids cover करती है।
  • Users जो daily scheduled automations चलाते हैं, जहां एक fast id recurring cost को flat रखती है और usage log उसे visible बनाता है।
  • Privacy-minded setups जो indexing और embeddings local रखते हैं और सिर्फ chat prompts एक auditable endpoint को expose करते हैं।
  • Tinkerers जो identical personal corpus पर chat models compare करते हैं: हर candidate same AI Model API के against एक chat-model row है।
  • Developers जिनके पास किसी given vendor की billing तक access नहीं है। बिना card requirement वाला top-up based access per-provider sign-up dependency हटा देता है।

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

पहले gateway check करें: अपनी key से models list करें और जिन ids को register करने की योजना है उन्हें confirm करें। Khoj की अपनी auto-discovery first-run seeding के दौरान वही call करती है, तो अगर यह curl काम करता है, seeding भी काम करेगी। Failures cleanly localize होती हैं। Authentication errors का मतलब है AI Model API entry पर Api Key गलत है या अभी भी seeded placeholder है। Model-not-found का मतलब है chat model Name catalog spelling से match नहीं करता। जो responses बीच में cut हो जाएं आमतौर पर मतलब है Max prompt size या model की output ceiling conversation के लिए बहुत कम set है। Indexing और search problems local embedding pipeline हैं और endpoint से इनका कोई लेना-देना नहीं। जब chats चलने लगें, APIsRouter console per-request model, token counts, और spend दिखाता है। Automations और research runs वह जगह हैं जहां second-brain costs छुपते हैं, और per-key usage इन्हें एक monthly surprise की बजाय per feature देखने का तरीका है।

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

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

क्या Khoj एक OpenAI-compatible proxy या gateway support करता है?

हां, एक documented setup के तौर पर: एक AI Model API entry बनाएं जिसका Api Base Url endpoint पर point करे, फिर Model Type Openai वाले chat models add करें। Compose file first-run seeding के लिए OPENAI_BASE_URL भी expose करती है।

क्या Khoj इसके through Claude या DeepSeek models से chat कर सकता है?

हां। Model Type Openai chat model Name को Api Base Url पर /v1/chat/completions के through एक plain string के तौर पर forward करता है। Gateway जो भी id serve करता है वह काम करती है, Claude, DeepSeek, GLM, और Gemini ids शामिल।

docker-compose में OPENAI_BASE_URL बदलने से कुछ क्यों नहीं हुआ?

यह variable सिर्फ first-run initialization के दौरान providers और models seed करता है। एक initialized server पर, इसकी बजाय admin panel में AI Model API entry edit करें; वही live setting है।

क्या custom base URL Khoj की document search पर असर डालता है?

नहीं। Khoj default रूप से एक local sentence-transformers model से आपके documents embed और search करता है। AI Model API entry सिर्फ chat, agents, automations, और research move करती है।

Chat model entry पर Max prompt size क्या है?

एक per-model cap कि Khoj एक request में कितना prompt pack करता है। इसे model की context window के फिट होने के लिए set करें; बहुत कम retrieved notes truncate करता है, और एक long-context id तभी मदद करती है जब यह field match करने के लिए raise की जाए।

क्या यह hosted Khoj app पर लागू होता है?

नहीं, custom endpoints एक self-hosting feature हैं। Hosted app अपने models server-side manage करता है; यहां वाले admin-panel और environment surfaces एक ऐसे server के हैं जो आप खुद चलाते हैं।