I've been creating a world where most-to-all of its life resides in the deep ocean. For story purposes, I would like said creature to have lungs, but it is not necessary.
Description of the Creature in Mind The creature in question is something along the lines of a massive sea serpent. Ideally, it would be able to either surface into an area that has air in it and be able to move on land, through legs or just by slithering along in a similar fashion to a snake. It lives around 2000 meters down, give or take ~500 meters.
Ecosystem of the Planet The planet is a large oceanic planet, which is slightly larger than Earth, and only has some small archipelagos for land. The plants of the planet primarily exist at the surface, as to the much smaller prey animals. small predators eat these smaller prey animals, but most animals who are purely "prey" don't exist very far down. Predators prey on smaller predators in a hierarchical type system, with the largest predators also bien the deepest. The creature would be in the mid-size range, but they have the advantage of being omnivores: there are massive underwater caverns that are filled with air. Very large plants, in some ways similar to those on Earth, grow in these caverns, and are adapted to using chemosynthesis to create energy, along with some small to mid size mammals and reptiles. This is really the only sizable prey besides smaller oceanic predators down this low, so the creature profits greatly from this resource. Due to much larger predators from below, they are forced to move around, and as these caverns, while common, are not common enough to allow for consistent breathing. These creatures do have large enough lungs to get to the surface, but this is impractical for them, as it would include long diving and surfacing sessions that may make to creature more vulnerable to predators.
By my understanding, there are many types of bacteria that could create oxygen as a waste resource, not through photosynthesis, but by some form of chemosynthesis, but I'm not certain. It is possible for a reasonably large creature (whale sized or larger) be able to host some form of bacteria in its body in a symbiotic relationship as a way of generating the oxygen that it needs to live? I'm presuming that the bacteria simply consumes some of the food that the creature eats, and then the oxygen created is somehow sent to the lungs.
If there are any other ideas as to how a creature of this size could get air, besides gills, as they collapse in while in regular air conditions, they would be helpful.