Optix throws error in the setAnyHitProgram method in material

In the optix sample,
method name - optix::Material createOptiXMaterial

mat->setAnyHitProgram(1u, any_hit ); this line throws the below error

“Invalid value (Details: Function “_rtMaterialSetAnyHitProgram” caught exception: Invalid ray type index: 1)”

can someone please help with this?

That would happen if there hasn’t been an rtContextSetRayTypeCount function call with a value of 2 or more before.
Please step through your code and see if there had been a sufficiently large raytype count set before that call.

OptiX API reference docs about those calls: