litellm/litellm
Marc Abramowitz ddf77656fb Allow non-admins to use OpenAI routes
The problem we were having is non-admin users trying to use
`/engines/{model}/chat/completions` were getting an HTTP 401 error.

```shell
$ curl -sSL 'http://localhost:4000/engines/gpt-35-turbo-0125/chat/completions' \
    --header "Authorization: Bearer ${LITELLM_KEY}" \
    --header 'Content-Type: application/json' \
    --data ' {
        "model": "gpt-35-turbo-0125",
        "messages": [
            {
                "role": "user",
                "content": "Write a poem about LiteLLM"
            }
        ]
    }' \
    | jq '.'
{
  "error": {
    "message": "Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route=/engines/gpt-35-turbo-0125/chat/completions. Your role=unknown. Your user_id=someone@company.com",
    "type": "auth_error",
    "param": "None",
    "code": 401
  }
}
```

This seems to be related to code in `user_api_key_auth` that checks that the URL
matches a list of routes that are allowed for non-admin users, where the list of
routes is in `LiteLLMRoutes.openai_routes.value`. The problem is that the route
`/engines/{model}/chat/completions` is not in that list and furthermore, that
wouldn't even work if it were, because the comparison is done with
`request.url.path` and that will have the actual model name in it (e.g.:
`gpt-35-turbo-0125`), rather than `{model}`.

I added a new list `LiteLLMRoutes.openai_route_names` and added the route
**names** to that list. Then I added a check in `user_api_key_auth` to see if
the route name is in the list of route names.
2024-05-15 17:36:11 -07:00
..
assistants feat(assistants/main.py): support litellm.get_assistants() and litellm.get_messages() 2024-05-04 21:30:28 -07:00
deprecated_litellm_server refactor: add black formatting 2023-12-25 14:11:20 +05:30
integrations fix(slack_alerting.py): fix timezone utc issue 2024-05-14 22:54:33 -07:00
llms fix(huggingface_restapi.py): fix task extraction from model name 2024-05-15 07:28:19 -07:00
proxy Allow non-admins to use OpenAI routes 2024-05-15 17:36:11 -07:00
router_strategy fix(lowest_latency.py): allow ttl to be a float 2024-05-15 09:59:21 -07:00
tests (ci/cd) fix test_content_policy_exception_azure 2024-05-15 14:47:39 -07:00
types fix(types/init.py): don't import openai assistants types by default 2024-05-15 08:50:31 -07:00
__init__.py docs(prod.md): add 'disable load_dotenv' tutorial to docs 2024-05-14 19:13:22 -07:00
_logging.py feat(utils.py): json logs for raw request sent by litellm 2024-04-29 19:21:19 -07:00
_redis.py feat(proxy_server.py): return litellm version in response headers 2024-05-08 16:00:08 -07:00
_service_logger.py fix(test_lowest_tpm_rpm_routing_v2.py): unit testing for usage-based-routing-v2 2024-04-18 21:38:00 -07:00
_version.py (fix) ci/cd don't let importing litellm._version block starting proxy 2024-02-01 16:23:16 -08:00
budget_manager.py feat(proxy_server.py): return litellm version in response headers 2024-05-08 16:00:08 -07:00
caching.py Merge pull request #3266 from antonioloison/litellm_add_disk_cache 2024-05-14 09:24:01 -07:00
cost.json store llm costs in budget manager 2023-09-09 19:11:35 -07:00
exceptions.py fix - show litellm_debug_info 2024-05-15 13:07:04 -07:00
main.py test: fix test 2024-05-15 08:51:40 -07:00
model_prices_and_context_window_backup.json fix(router.py): fix validation error for default fallback 2024-05-15 13:23:00 -07:00
requirements.txt Add symlink and only copy in source dir to stay under 50MB compressed limit for Lambdas. 2023-11-22 23:07:33 -05:00
router.py fix(router.py): fix validation error for default fallback 2024-05-15 13:23:00 -07:00
timeout.py refactor: add black formatting 2023-12-25 14:11:20 +05:30
utils.py fix - show litellm_debug_info 2024-05-15 13:07:04 -07:00