Skip to content

Support dynamic apiKey #2215

@AlexanderYastrebov

Description

@AlexanderYastrebov

Validations

  • I believe this is a way to improve. I'll try to join the Continue Discord for questions
  • I'm not able to find an open issue that requests the same enhancement

Problem

In our environment we'd like to use custom model served via proxy.
This proxy requires API key that user may obtain via pre-installed authentication tool (get_token).
The proposal is to support dynamic API key by using standard output of the tool.

Solution

Possible solution could be to modify config.ts such that it executes the tool:

const { execSync } = require("child_process");

export function modifyConfig(config: Config): Config {
  config.models
    .filter(model => model.apiKey && model.apiKey.startsWith("$"))
    .forEach((model) => {
      const cmd = model.apiKey.substr(1).trim();
      Object.defineProperty(model, "apiKey", {
        get() {
          return execSync(cmd, { encoding: "utf8" }).trim();
        },
      });
    });
  return config;
}

and config.json

{
  "models": [
    {
      "title": "myLLM",
      "provider": "openai",
      "model": "bar/baz",
      "apiBase": "https://example.com/v1",
      "apiKey": "$ get_token"
    }
  ],
...

Another option is to allow apiKey to be a function:

const { execSync } = require("child_process");

export function modifyConfig(config: Config): Config {
  config.models
    .filter(model => model.apiKey && model.apiKey.startsWith("$"))
    .forEach((model) => {
      const cmd = model.apiKey.substr(1).trim();
      model.apiKey = () => {
        return execSync(cmd, { encoding: "utf8" }).trim();
      };
    });
  return config;
}

The challenge is to ensure that apiKey property getter is invoked each time its needed to refresh the value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:configurationRelates to configuration optionskind:enhancementIndicates a new feature request, imrovement, or extensionstale

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions