AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Connect Custom API Keys and Index Workspace Context in CodeGPT for VS Code

365Finds Editorial
Indexed 11,430 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

To turn CodeGPT into a repository-aware coding companion inside Visual Studio Code, developers must solve two fundamental requirements: providing model access through custom API keys (Bring Your Own Key / BYOK) and grounding responses in their project through local codebase indexing. Once configured, CodeGPT uses semantic search and multi-profile agents to explain complex logic across files and execute surgical refactoring directly within the editor.

This guide details how to configure custom providers, build workspace vector context, and orchestrate code explanations and refactorings using CodeGPT's built-in tools.


1. Connecting Custom API Keys (BYOK & Custom Endpoints)

CodeGPT operates on a hybrid model: new users receive a limited free tier (30 monthly interactions), but serious development typically relies on Bring Your Own Key (BYOK) or team subscriptions. Using BYOK grants unlimited interactions through CodeGPT, with API token consumption billed directly by your LLM provider.

Step-by-Step Provider Setup

  1. Install and Sync: Install the official CodeGPT: AI Coding Agents & Chat extension (published by DanielSanMedium) from the VS Code Marketplace. Open the CodeGPT sidebar and log in using Google, GitHub, or email to sync your account.
  2. Access Provider Settings:
    • In the CodeGPT chat sidebar, click the Manage Models button and switch to the Providers tab.
    • Alternatively, open the VS Code Command Palette (Ctrl+Shift+P on Linux/Windows, Cmd+Shift+P on macOS) and run CodeGPT: Set API KEY.
  3. Select Your AI Provider:
    • CodeGPT provides native connectors for OpenAI, Anthropic, Google AI Studio, DeepSeek, Mistral, Cohere, Groq, Cerebras, Perplexity, and local engines like Ollama and LM Studio.
    • Paste the secret API key generated from your provider console (such as OpenAI's platform settings or Anthropic's console).
    • Enter your Organization ID if required by your account.
  4. Configuring Custom OpenAI-Compatible Endpoints:
    • If you use self-hosted inference, internal enterprise gateways, or specialized aggregators (like OpenRouter or vLLM), select Custom under the provider list.
    • Enter your target Model Name (e.g., cognitivecomputations/dolphin3.0-mistral-24b:free or your custom fine-tuned model tag).
    • Enter your API Key.
    • Input the full Custom Link (the /chat/completions HTTP endpoint).
    • Click Connect.
  5. Critical Post-Configuration Step: When using the BYOK plan, you must explicitly select an active model from the chat interface's model selector before sending prompts. Attempting to submit prompts without a selected model triggers a "You must select a model first" error.

2. Indexing Local Workspace Context (Augmented Context)

By default, an AI model in an IDE only knows what you paste into the chat window or the code you currently highlight. To assist with cross-file explanations and safe refactoring, CodeGPT offers Codebase Indexing (Augmented Context).

Highlighting vs. Codebase Indexing

How to Create the Workspace Index

  1. In the CodeGPT extension sidebar, locate the main menu and click the Codebase button under Augmented Context.
  2. Click Create Codebase Index.
  3. Select your project folder from the folder selection dialog.
  4. CodeGPT parses your project files and builds a local vector index.
  5. Once indexing completes, the assistant automatically enables the Semantic Search Tool.

Injecting Context into Conversations

CodeGPT provides three primary ways to reference workspace files during conversations:


3. Explaining Code Across the Workspace

Deciphering legacy code or unfamiliar architectural patterns requires both local syntax inspection and repository-wide context.

Recommended Profile Mode: Search Mode

CodeGPT provides three pre-configured profile modes in the chat dropdown:

Workflow for Code Explanation

  1. Select Code: In the VS Code editor, highlight the function, class, or tricky block of logic you want to understand.
  2. Execute /Explain:
    • Open the CodeGPT chat interface, type /Explain, and press Enter.
    • Alternatively, right-click the selected code in the editor and choose Explain CodeGPT from the context menu.
  3. Repository-Aware Synthesis: Because the codebase is indexed, CodeGPT traces where parameters originate, how called helpers are implemented elsewhere in your repository, and which edge cases the implementation handles.
  4. Follow-Up Inquiries: In Search Mode, ask specific questions like:
    • "Where is this handler called across the workspace?"
    • "Explain how authentication middleware impacts this route handler."

4. Refactoring Code with Full Workspace Awareness

Refactoring without context often breaks call signatures, introduces naming mismatches, or violates project linting standards. CodeGPT enables safe refactoring through structured slash commands and progressive tool permissions.

Refactoring Workflow

  1. Isolate Target Code: Highlight the code snippet or block targeted for modernization, cleanup, or performance optimization.
  2. Trigger /Refactor:
    • In the CodeGPT chat input, type /Refactor followed by specific constraints (for example: /Refactor convert callback chain to async/await and extract validation logic), then press Enter.
    • Alternatively, right-click and choose Refactor CodeGPT.
  3. Review and Application:
    • In Search or Chat Mode: CodeGPT outputs a structured diff and clean replacement block in the chat panel. Click the Insert code button (the arrow icon in the top right of the code block) to insert the replacement directly into your active VS Code document.
    • In Agent Mode: CodeGPT invokes its internal Edit File tool to apply modifications directly to disk. If Auto-Approve is disabled in Settings, CodeGPT prompts you to inspect and approve the change before writing.

Practical Tips for Reliable Refactoring


References