()
| 682 | # Optional API key configuration to secure the proxy |
| 683 | @app.before_request |
| 684 | def check_api_key(): |
| 685 | if server_config['optillm_api_key']: |
| 686 | if request.path == "/health": |
| 687 | return |
| 688 | |
| 689 | auth_header = request.headers.get('Authorization') |
| 690 | if not auth_header or not auth_header.startswith('Bearer '): |
| 691 | return jsonify({"error": "Invalid Authorization header. Expected format: 'Authorization: Bearer YOUR_API_KEY'"}), 401 |
| 692 | |
| 693 | client_key = auth_header.split('Bearer ', 1)[1].strip() |
| 694 | if not secrets.compare_digest(client_key, server_config['optillm_api_key']): |
| 695 | return jsonify({"error": "Invalid API key"}), 401 |
| 696 | |
| 697 | @app.route('/v1/chat/completions', methods=['POST']) |
| 698 | def proxy(): |
nothing calls this directly
no outgoing calls
no test coverage detected