Use a language model with Dev Proxy

At a glance
Goal: Configure a local or hosted LLM for Dev Proxy features
Time: 10 minutes
Plugins: OpenAIMockResponsePlugin
Prerequisites: Set up Dev Proxy, local LLM host (e.g., Ollama) or access to a hosted LLM (e.g., OpenAI, GitHub Models, Azure OpenAI)

By connecting Dev Proxy to a language model, you can improve Dev Proxy's functionality. Select Dev Proxy plugins use the language model to improve their output, where natural language is involved. By using a local language model, you can benefit from the improved functionality without incurring extra costs. If you can't run a model locally, you can connect Dev Proxy to a hosted language model instead.

Prerequisites

Dev Proxy supports language model hosts that expose OpenAI-compatible APIs, such as Ollama, OpenAI, GitHub Models, or OpenRouter. It also has support for Ollama APIs and Azure OpenAI. To configure a local language model host, follow the instructions in its documentation. To use a hosted language model, get the endpoint URL, the model name, and an API key from your provider.

Configure Dev Proxy to use a local language model

To configure Dev Proxy to use a local language model, use the languageModel setting in the devproxyrc.json file.

File: devproxyrc.json

{
  "languageModel": {
    "enabled": true
  }
}

You can use the following options as part of the languageModel setting:

Option Description Default value
apiKey API key for hosted language models. Dev Proxy sends it as a Bearer token for the OpenAI and Ollama clients, and in the api-key header for the AzureOpenAI client. Use @env:VAR_NAME to read the key from an environment variable. none
cacheResponses Specifies whether to cache responses from the language model. true
client The type of the client to use. Allowed values: Ollama, OpenAI, AzureOpenAI. Use OpenAI for any OpenAI-compatible endpoint. OpenAI
enabled Specifies whether to use a language model. false
model The name of the language model to use. For Azure OpenAI, the name of the model deployment. llama3.2
url The base URL of the language model API. http://localhost:11434/v1/

By default, Dev Proxy uses the standard Ollama configuration with the llama3.2 model using Ollama's OpenAI-compatible APIs. It also caches responses from the language model, which means, that for the same prompt, you get an immediate response without waiting for the language model to process it.

Important

When using a local language model, be sure to start your local language model client before starting Dev Proxy.

Configure Dev Proxy to use a hosted language model

To use a hosted language model, set the url, model, and apiKey options in the languageModel setting.

Important

Don't store API keys in your configuration file. Instead, store the key in an environment variable and reference it using the @env:VAR_NAME syntax, for example "apiKey": "@env:OPENAI_API_KEY". Dev Proxy doesn't log the API key.

OpenAI-compatible endpoints

To use OpenAI or any other OpenAI-compatible endpoint, such as GitHub Models or OpenRouter, use the OpenAI client and set url to the base URL of the API. Dev Proxy sends the API key as a Bearer token in the Authorization header.

File: devproxyrc.json

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v4.1.0/rc.schema.json",
  "languageModel": {
    "enabled": true,
    "client": "OpenAI",
    "model": "gpt-4.1-mini",
    "url": "https://api.openai.com/v1/",
    "apiKey": "@env:OPENAI_API_KEY"
  }
}

Azure OpenAI

To use Azure OpenAI, use the AzureOpenAI client. Set url to the Azure OpenAI v1 API endpoint (https://<resource>.openai.azure.com/openai/v1/) and model to the name of your model deployment. The AzureOpenAI client requires an API key, which Dev Proxy sends in the api-key header. If you don't set the API key, Dev Proxy disables the language model.

File: devproxyrc.json

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v4.1.0/rc.schema.json",
  "languageModel": {
    "enabled": true,
    "client": "AzureOpenAI",
    "model": "gpt-4.1-mini",
    "url": "https://<resource>.openai.azure.com/openai/v1/",
    "apiKey": "@env:AZURE_OPENAI_API_KEY"
  }
}

Before you start Dev Proxy, set the environment variable with your API key. For example, on macOS or Linux:

export AZURE_OPENAI_API_KEY=<your-api-key>
devproxy

If the environment variable isn't set, Dev Proxy shows a warning and continues without an API key.

Note

Using a hosted language model might incur costs. Dev Proxy caches responses by default (cacheResponses), so it doesn't send the same prompt to the language model more than once.

Language model availability check

When Dev Proxy starts, it checks if the configured language model is available. When you use the OpenAI or AzureOpenAI client, to avoid incurring costs, Dev Proxy first calls the GET {url}/models endpoint instead of sending a completion request:

  • If the endpoint returns a successful response that lists the configured model, Dev Proxy enables the language model. Dev Proxy also matches models listed with the :latest tag, like Ollama does, for example llama3.2:latest.
  • If the endpoint returns 401 Unauthorized, Dev Proxy disables the language model and shows an error. Check the configured API key.
  • For Azure OpenAI, if the endpoint returns a successful response, Dev Proxy enables the language model. Azure OpenAI lists base models rather than deployments, so Dev Proxy doesn't look for the deployment name in the list.
  • In other cases, for example when the language model host doesn't support the /models endpoint or doesn't list the configured model, Dev Proxy falls back to sending a completion request to verify that the language model is available.

Dev Proxy plugins that can use a language model

The following Dev Proxy plugins require a language model. If you don't enable a language model, Dev Proxy disables these plugins:

The following Dev Proxy plugins use a language model if available:

See also