/ documentation / docs / advanced / litellm.md
litellm.md
 1  # LiteLLM
 2  :::info
 3  This is only helpful for self-hosted users. If you're using [Khoj Cloud](https://app.khoj.dev), you're limited to our first-party models.
 4  :::
 5  
 6  :::info
 7  Khoj natively supports local LLMs [available on HuggingFace in GGUF format](https://huggingface.co/models?library=gguf). Using an OpenAI API proxy with Khoj maybe useful for ease of setup, trying new models or using commercial LLMs via API.
 8  :::
 9  
10  [LiteLLM](https://docs.litellm.ai/docs/proxy/quick_start) exposes an OpenAI compatible API that proxies requests to other LLM API services. This provides a standardized API to interact with both open-source and commercial LLMs.
11  
12  Using LiteLLM with Khoj makes it possible to turn any LLM behind an API into your personal AI agent.
13  
14  ## Setup
15  1. Install LiteLLM
16     ```bash
17     pip install litellm[proxy]
18     ```
19  2. Start LiteLLM and use Mistral tiny via Mistral API
20     ```
21     export MISTRAL_API_KEY=<MISTRAL_API_KEY>
22     litellm --model mistral/mistral-tiny --drop_params
23     ```
24  3. Create a new [API Model API](http://localhost:42110/server/admin/database/aimodelapi/add) on your Khoj admin panel
25     - **Name**: `litellm`
26     - **Api Key**: `any string`
27     - **Api Base Url**: `<URL of your Openai Proxy API>`
28  4. Create a new [Chat Model](http://localhost:42110/server/admin/database/chatmodel/add) on your Khoj admin panel.
29     - **Name**: `llama3.1` (replace with the name of your local model)
30     - **Model Type**: `Openai`
31     - **Ai Model Api**: *the litellm Ai Model API you created in step 3*
32     - **Max prompt size**: `20000` (replace with the max prompt size of your model)
33     - **Tokenizer**: *Do not set for OpenAI, Mistral, Llama3 based models*
34  5. Go to [your config](http://localhost:42110/settings) and select the model you just created in the chat model dropdown.