How to Configure DeepWiki for Custom Model Providers: OpenAI, Google, OpenRouter, Azure, and Ollama

DeepWiki loads model provider configurations from JSON files in api/config/ and environment variables at startup, mapping provider IDs to client classes via the CLIENT_CLASSES dictionary in api/config.py to support OpenAI, Google, OpenRouter, Azure, and Ollama without modifying core code.

DeepWiki uses a pluggable architecture that separates model provider configuration from implementation. By editing JSON configuration files and setting environment variables, you can configure DeepWiki for custom model providers including OpenAI, Google, OpenRouter, Azure, and Ollama. This guide explains the configuration system implemented in api/config.py and provides specific setup instructions for each supported provider.

How DeepWiki Configuration Works

DeepWiki initializes its model provider system at startup through a three-layer configuration process defined in api/config.py. The system first reads environment variables for API keys and endpoints, then loads JSON configuration files from the api/config/ directory, and finally maps provider definitions to concrete client implementations.

The configuration loader performs these steps:

  1. Environment variable ingestion (api/config.py lines 18-28): Reads API keys, base URLs, and the optional DEEPWIKI_CONFIG_DIR override.
  2. JSON file loading: Loads generator.json for LLM providers and embedder.json for embedding providers via load_json_config().
  3. Client class resolution (api/config.py lines 57-66): Maps provider IDs to client classes using the CLIENT_CLASSES dictionary.
  4. Configuration assembly: load_generator_config() (lines 27-46) attaches the resolved client class to each provider entry.
  5. Runtime retrieval: get_model_config() (lines 59-68) returns the final configuration dict containing model_client and model_kwargs ready for AdalFlow Generator or Embedder components.

Step 1: Set Environment Variables for API Keys

DeepWiki reads provider credentials from environment variables at import time. Set these variables before starting the application:

  • OpenAI: OPENAI_API_KEY
  • Google: GOOGLE_API_KEY
  • OpenRouter: OPENROUTER_API_KEY
  • Azure OpenAI: AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_VERSION
  • Ollama: OLLAMA_HOST (defaults to http://localhost:11434)

You can also override the configuration directory:

export DEEPWIKI_CONFIG_DIR="/path/to/custom/configs"

Step 2: Configure JSON Provider Definitions

Provider definitions reside in api/config/generator.json (for LLMs) and api/config/embedder.json (for embeddings). Each entry specifies the client class, default model, and model parameters.

Generator Configuration Structure

A typical provider block in generator.json contains:

{
  "provider_id": "openai",
  "client_class": "OpenAIClient",
  "default_model": "gpt-4o",
  "model_kwargs": {
    "temperature": 0.7,
    "top_p": 0.9
  }
}

Embedder Configuration Structure

The embedder.json file follows a similar pattern, specifying the embedding model and batch processing parameters:

{
  "provider_id": "google",
  "client_class": "GoogleEmbedderClient",
  "default_model": "text-embedding-004",
  "batch_size": 100
}

Step 3: Map Client Classes

The CLIENT_CLASSES dictionary in api/config.py (lines 57-66) maps provider IDs to concrete client implementations. When load_generator_config() processes a JSON entry, it resolves the "client_class" field using this mapping.

Default mappings include:

To add a new provider, import your client class in api/config.py and add it to CLIENT_CLASSES.

Provider-Specific Configuration Examples

OpenAI Configuration

OpenAI uses the standard client in api/openai_client.py. Set your API key and ensure the generator.json entry uses "client_class": "OpenAIClient".

from adalflow import Generator
from api.openai_client import OpenAIClient

gen = Generator(
    model_client=OpenAIClient(),
    model_kwargs={"model": "gpt-4o", "stream": True}
)

resp = gen({"input_str": "Explain Deep Wiki architecture."})
print(resp.data)

Google Generative AI Configuration

For Google embeddings, use the GoogleEmbedderClient from api/google_embedder_client.py:

from adalflow import Embedder
from api.google_embedder_client import GoogleEmbedderClient

embedder = Embedder(
    model_client=GoogleEmbedderClient(),
    model_kwargs={"model": "text-embedding-004", "task_type": "SEMANTIC_SIMILARITY"}
)

texts = ["Deep Wiki is a knowledge‑base tool.", "It stores articles as XML."]
emb = embedder(input=texts)
print(emb.data[0].embedding[:5])

OpenRouter Configuration

OpenRouter provides a unified API for multiple models. Use the OpenRouterClient from api/openrouter_client.py:

import os
from adalflow import Generator
from api.openrouter_client import OpenRouterClient

os.environ["OPENROUTER_API_KEY"] = "your-key"

gen = Generator(
    model_client=OpenRouterClient(),
    model_kwargs={"model": "anthropic/claude-3.5-sonnet", "stream": False}
)

print(gen({"input_str": "Summarize the latest AI news."}).data)

Azure OpenAI Configuration

Azure OpenAI supports both API key and Azure AD authentication via api/azureai_client.py:

import os
from adalflow import Generator
from api.azureai_client import AzureAIClient

os.environ["AZURE_OPENAI_ENDPOINT"] = "https://my‑endpoint.openai.azure.com/"
os.environ["AZURE_OPENAI_VERSION"] = "2023-05-15"

gen = Generator(
    model_client=AzureAIClient(),
    model_kwargs={"model": "gpt-4o", "stream": True}
)

print(gen({"input_str": "How does Azure AD work?"}).data)

Ollama Local Configuration

Ollama runs locally without API keys. Set OLLAMA_HOST and use the OpenAI-compatible client:

import os
from adalflow import Generator
from api.openai_client import OpenAIClient

os.environ["DEEPWIKI_EMBEDDER_TYPE"] = "ollama"
os.environ["OLLAMA_HOST"] = "http://localhost:11434"

gen = Generator(
    model_client=OpenAIClient(),
    model_kwargs={"model": "qwen3:1.7b", "stream": True}
)

print(gen({"input_str": "What is Ollama?"}).data)

Summary

  • DeepWiki configures model providers through environment variables (API keys, endpoints) and JSON configuration files (generator.json, embedder.json) located in api/config/.
  • The CLIENT_CLASSES dictionary in api/config.py maps provider IDs to concrete client implementations such as OpenAIClient, GoogleEmbedderClient, and AzureAIClient.
  • Override the default configuration directory by setting DEEPWIKI_CONFIG_DIR before startup.
  • Select embedding providers by setting DEEPWIKI_EMBEDDER_TYPE to values like openai, google, or ollama.

Frequently Asked Questions

How do I add a completely new model provider that is not in the default configuration?

Create a new client class inheriting from adalflow.core.model_client.ModelClient and place it in the api/ directory. Import this class in api/config.py and add it to the CLIENT_CLASSES dictionary with a unique string key. Finally, create a JSON entry in generator.json or embedder.json referencing this client class name.

Can I use different providers for generation and embeddings simultaneously?

Yes. Set DEEPWIKI_EMBEDDER_TYPE to select the embedding provider (e.g., google for Google embeddings) while configuring the generator provider separately in generator.json or via runtime client selection. The system maintains separate configuration dictionaries for generators and embedders.

Where should I store sensitive API keys to keep them out of the JSON files?

Store API keys exclusively in environment variables. The configuration loader in api/config.py reads keys like OPENAI_API_KEY, AZURE_OPENAI_API_KEY, and OPENROUTER_API_KEY at startup. The JSON configuration files should only contain non-sensitive parameters like model names, temperature settings, and client class references.

How do I override the default configuration directory location?

Set the DEEPWIKI_CONFIG_DIR environment variable to point to your custom directory containing generator.json and embedder.json files. The loader function load_json_config() in api/config.py prepends this path when opening configuration files, allowing you to maintain custom configurations outside the repository.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →