bricks-cloud / BricksLLM

🔒 Enterprise-grade API gateway that helps you monitor and impose cost or rate limits per API key. Get fine-grained access control and monitoring per user, application, or environment. Supports OpenAI, Azure OpenAI, Anthropic, vLLM, and open-source LLMs.
https://trybricks.ai/
MIT License
863 stars 60 forks source link

Do not run policy if policyInput is not assigned a value #58

Closed donfour closed 3 months ago

donfour commented 3 months ago

Issue

When using a secret key with a policy to make a request to POST /api/providers/openai/v1/assistants, OpenAI returns this error:

{'error': {'message': "Missing required parameter: 'assistant_id'.", 'type': 'invalid_request_error', 'param': 'assistant_id', 'code': 'missing_required_parameter'}}

This is because when a p exists but policyInput is nil, json.Marshal fails and the request body does not get reset. Hence we're forwarding an empty request body to OpenAI, causing OpenAI to return an error.

Fix

Fix is to add a check to see if policyInput exists before running p.Filter.