Is it correct to say "When it started to rain, I was in the open air"?
This is fine, though being "in the open" implies being "in the open air". (This is Earth, not the vacuum of space, or under the water, so it would sound odd.)
Or should I say "I was not inside a building"?
Only if you specifically want to tell them that you weren't in a building.
This is because there are other places you could be when it started to rain besides in the open or in a building. For example, you could be:
- on the porch,
- under an overhang,
- in a car port,
- any other place that shelters you from the rain which aren't in doors.
In all those cases, you are outside, but definitely not "in the open".