BerriAI/liteLLM-proxy

Unauthorized

Closed this issue · 10 comments

No matter what I do, I get an 401 Unauthorized response back.

I tried using the .env and setting up my OpenAI key.
I tried using Bearer Auth header with my OpenAI key.

Here is the json body I'm sending via PostMan:

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "content": "Hello, whats the weather in San Francisco??",
      "role": "user"
    }
  ]
}

I've also tried accessing TogtherAI models and am having the same problem.
Using the latest git version.

Hey @gururise,

The key needed to pass in via bearer is the user key -

see user_key_auth: https://github.com/BerriAI/liteLLM-proxy/blob/bbe0f62e3a413c184607a188ec1b9ca931fef040/main.py#L65C63-L65C63

it checks if the user key is valid here -

user_api_keys = set(budget_manager.get_users())

You can create a user key by calling /key/new:

async def generate_key(request: Request):

--
We're assuming you have your api keys in the .env and trying to provide users access to this.

Let me know if that works for you. Happy to hop on a call and help debug as well.

Hey @gururise,

The key needed to pass in via bearer is the user key -

see user_key_auth: https://github.com/BerriAI/liteLLM-proxy/blob/bbe0f62e3a413c184607a188ec1b9ca931fef040/main.py#L65C63-L65C63

it checks if the user key is valid here -

user_api_keys = set(budget_manager.get_users())

You can create a user key by calling /key/new:

async def generate_key(request: Request):

-- We're assuming you have your api keys in the .env and trying to provide users access to this.

Thanks, took some time to figure out, but here's what I did:

  1. I set the environment variable USERS_KEYS="abcd"
  2. Set the Bearer Token to abcd
  3. Hit the /key/new endpoint and POST the payload: {'total_budget':100000}
  4. I get the userkey -> sk-litellm-V9uBaddAR6muMVn0ZwNViw

I then try to hit the /chat/completions post endpoint, passing the payload:

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "content": "Hello, whats the weather in San Francisco??",
      "role": "user"
    }
  ]
}

Now I get the results back...

Is there a way to not require a userkey?

Yea just comment out this dependencies line -

@app.post("/chat/completions", dependencies=[Depends(user_api_key_auth)])

hmm how do plan on giving users access to your api keys if you remove this? @gururise

hmm how do plan on giving users access to your api keys if you remove this? @gururise

What I meant is, I would like to pre-define a user-key (in the env file) that could be used and never changes upon app restarts.

Oh - then just modify this line to be the key in your .env

Are you setting budget limits etc. on this key?

Oh - then just modify this line to be the key in your .env

Are you setting budget limits etc. on this key?

No budget limits. Just want unlimited usage.

oh yea that 1 line change should solve your problem. Curious - why use the proxy? @gururise