Costa Rican standoff
During the night, this caterpillar (Oxytenis modestia) moved onto and began feeding on a leaf directly above the nest of a rufous-tailed hummingbird (Amazilia tzacatl), whose comings and goings disturbed the caterpillar, causing it to expand and reveal its "eyes" and rear up into its snake-mimic posture.
For about 30 minutes, the hummingbird hovered all around the caterpillar, repeatedly pecking and biting its eyespots. Ultimately, the unharmed caterpillar turned around and crawled off the leaf. It was later found in the far top corner of the small tree (Rubiaceae), as far as it could get from the hummingbird nest. Two days later the two hummingbird eggs hatched and the caterpillar was nowhere to be found, most likely having crawled off to pupate and become an adult moth.
Final instar caterpillar of the moth, Oxytenis modestia (Saturniidae). When disturbed, the caterpillar increases its internal pressure, causing the area behind the head to expand and expose a pair of eyespots. Expansion and exposure of the "eyes" is accompanied by rearing up and side to side movements, which closely mimic a small snake.
Same caterpillar as previous photo but with thorax region expanded and eyespots exposed. This photo was taken after the run-in with the hummingbird and I can find no evidence of injury but a few small beak marks. I suspect that the eyespot area is relatively tough and a good location to deflect attacks. The more delicate head is tucked underneath, with just the top visible at bottom left.
Here is the snake that I think the Oxytenis caterpillar most closely mimics. This is the Green Parrot Snake (Leptophis ahaetulla), which I photographed at the same location (another shrub, a few meters away) on an earlier trip to Campanario. On multiple occasions we have found this species in shrubs at the border between primary forest and open areas, precisely where Rufous-tailed hummingbirds defend territories and have their nests. Spanish names are Bejuquillo verde, lora falsa gigante.