Skip to content

handling of api-key-name not always working when using aliases for custom providers #1568

Description

@schluenz

Problem

I'm using jupyter-ai v3.0.0 for custom providers like for example blablador. To do so, I define an alias:

%ai alias blablador-code openai/alias-code --api-base https://api.blablador.fz-juelich.de/v1 --api-key-name BLABLADOR_API_KEY

Authentication however doesn't work. It looks like that the api-key-name is not good enough.

Proposed Solution

a simple workaround would be to pass on the api-key rather than the api-key-name inside magics.py:

diff magics.py.orig magics.py 
340c340
<             # Add API key from .env if api_key_name is provided
---
>             # Add API key if api_key_name is provided
342,345c342,344
<                 # Retrieve the actual API key from the .env file
<                 api_key_name_value = os.getenv(args.api_key_name)
<                 if not api_key_name_value:
<                     error_msg = f"API key '{args.api_key_name}' not found in .env file."
---
>                 api_key_value = os.getenv(args.api_key_name)
>                 if not api_key_value:
>                     error_msg = f"API key '{args.api_key_name}' not found in environment."
348c347,353
<                 completion_args["api_key_name"] = api_key_name_value
---
>                 completion_args["api_key"] = api_key_value
>             else:
>                 # Fall back to OPENAI_API_KEY from environment explicitly,
>                 # since litellm doesn't always pick it up via alias
>                 api_key_value = os.getenv("OPENAI_API_KEY")
>                 if api_key_value:

That works smoothly with my custom providers, but I didn't try anything beyond that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    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