Lurch will bite when I'm scritching him if I hit a pin feather, though now that we've mostly bonded and come to terms with each other he mostly just growls and I say sorry and we continue. I do try to watch him a bit as I think they can get overstimulated or tired of it and get nippy too.
Also he may have seen something that alarmed him so he reacted and you got a bite, or he just had a scary thought who knows. Lurch has many triggers that will make him go crazy and try to attack, like a hat on me he doesn't know, no glasses on my face, doing something that I don't normally do, plus the hormonal times too.
He pretty much loves us now but he's a grumpy fellow who sometimes just decides he doesn't want to be messed with and we try and respect that. And I react too most times, he has punched holes in my earlobes before when I got him triggered and he suddenly decided I looked wrong or didn't offer my breakfast fast enough.
He was very quick about biting when he first got here over 5 years ago, I slowly worked with him and he slowly decided I didn't need immediate correction bites as I think he now knows we respect his warnings and he does care for us now so he doesn't always try as fast or hard as he used too.
You'll have to learn his triggers and work with him, it's a mutual thing, he's learning you, and your learning him and eventually you'll reach a mutual understanding where he wont bite most times without a reason you both understand but it'll take a bit to get there.
I don't react as much to small nips and pokes with the side of his beak as I see it as more of a warning then a actual bite, and usually tell him to be a good boy and let him stay, if he does a real bad bite we have a talk and he gets shooed away till he decides to be nice again, he hates being away from us.
Good luck and remember he's a jungle creature and has his own rules, you'll get there, just take the long term approach.