add openai middleware functionality fix critical type errors and linting issues update readme with middleware documentation