-
Notifications
You must be signed in to change notification settings - Fork 123
AI Completions
C# REPL can suggest code completions using an AI model. Suggestions are generated from the code you have typed in the current session, so they are aware of the variables, methods, and types you have already defined. You bring your own API key, and usage is billed to your provider account.
Press Ctrl+Alt+Space at the caret to request a completion. The generated code is streamed directly into the prompt at the caret position as it arrives — there is no separate suggestion to accept; it simply appears as input you can then edit or run.
The feature is silently disabled until an API key is available (see below), so the default REPL needs no AI configuration.
C# REPL is provider-agnostic: it talks to any OpenAI-compatible chat-completions endpoint. Several providers are built in as presets, selected with --aiProvider. Each preset knows which environment variable to read its API key from, which endpoint to call, and a sensible default model.
--aiProvider |
API-key environment variable | Default model |
|---|---|---|
openai (default) |
OPENAI_API_KEY |
gpt-5.4-mini |
anthropic |
ANTHROPIC_API_KEY |
claude-sonnet-4-6 |
gemini |
GEMINI_API_KEY |
gemini-2.5-flash |
grok |
XAI_API_KEY |
grok-4.3 |
deepseek |
DEEPSEEK_API_KEY |
deepseek-chat |
mistral |
MISTRAL_API_KEY |
mistral-large-latest |
codestral |
CODESTRAL_API_KEY |
codestral-latest |
Default models drift over time; override any of them with --aiModel.
- Get an API key from your provider.
- Make it available to C# REPL, either:
- set the environment variable for your provider (the table above), or
- pass
--aiApiKey <key>at startup.
- If you are not using OpenAI, select your provider with
--aiProvider <name>.
For example, to use Anthropic:
# set ANTHROPIC_API_KEY in your environment, then:
csharprepl --aiProvider anthropicAny service exposing an OpenAI-compatible /chat/completions endpoint works, even if it is not in the table above (for example Azure OpenAI, a local Ollama server, or another hosted provider). Point C# REPL at it with --aiEndpoint, and supply the model and key yourself:
csharprepl --aiEndpoint http://localhost:11434/v1 --aiModel llama3 --aiApiKey ollamaWhen --aiProvider is set to a name that is not a known preset, C# REPL treats it as a custom endpoint: no environment variable is read for you, so you must provide --aiEndpoint, --aiModel, and --aiApiKey explicitly.
Set these at the command line or in your config file (see Configuring CSharpRepl):
-
--aiProvider <name>: provider preset to use. Default:openai. -
--aiApiKey <key>: API key for the provider. Overrides the provider's environment variable. -
--aiEndpoint <url>: base URL of an OpenAI-compatible API. Overrides the selected provider's default endpoint. -
--aiModel <model>: model to use. Overrides the selected provider's default model. -
--aiPrompt <prompt>: system prompt prefixed to every submission. -
--aiHistoryCount <count>: how many previous REPL entries to send as context. Default:5.