Pirates are always a threat, but this particular coastal city has another worry - wyverns. In order to get from said city to open seas, the ships must traverse about 600km towards the exit from the Bay, and as it happens the wyverns nest on southern shore, which means that its common for these creatures to be flying over the entire bay. As they are also hunting here, it inevitably means that ships also get attacked.
How would the humans effectively defend their ships against these creatures?
The focus is on safety of the crew and ship, not necessarily on killing the wyvern.
More about the wyverns
EDIT:What I describe here as a wyvern is my version/take on it and as such it is different than the common depiction of a wyvern.
A wyvern is essentially a snake, with bat-like wings attached to its ribcage and a rather muscular pair of legs located in the hind section of its body. An adult wyvern we expect to encounter can range from 15 to 40 meters in length and about 35-60m in wingspan. It's entire body with exception of wings is covered with scales which offer protection similar to plate armor - arrows will likely bounce off at medium and long ranges, but crossbow bolts are more likely to penetrate.
The wyevern has an animal level of intelligence (it is not an intelligent race), heavily reliant on instincts. It exhibits no magical abilities.
Why do wyverns attack ships?
They mistake them for prey - basking whales.
How do wyverns attack?
Two options:
Diving attack
If a wyvern is at high altitude (over 1000m) it will dive down towards the target. Contact with prey will be made with jaws first, legs second. Wyverns were reported to kill whales with sheer force of impact with this method.
Level attack
If a wyvern is at low altitudes it will usually circle the target first. If it comes to the conclusion that sails do actually look like whale blow, it will attack in a swooping manner, heading directly at the target, seeking to strike with legs first.
The diving attack is more common, because a wyvern investigating a target in the second method will often realize that it's not a whale and leave. High-flying wyverns are also more commonly enocuntered. Wyverns can occasionally be encountered swimming in the water, but they do not display predatory behavior when not in the air and will leave if disturbed.
What if a wyvern successfully attacks a ship?
It will get very confused about biting into a piece of wood with humans crawling over it, rather than a juicy whale. It will leave, but at that point the damage to ship and crew has already been done. Smaller ships can be outright sunk.
More about technology
The ships in use are wooden sailing ships ranging from ships similar to cogs, carracks and caravels to ships more like the galleons or brigantines. Technology level could be described as roughly that of high middle ages in most aspects. Magic exists, but mages are rare.
No gunpowder weapons are in use.
Bows and crossbows are most common ranged weapons, and various siege engines are also in use in warfare.
Things I've considered
Siege engines similar to ballista or scorpion seem to be my first thought, though there are several issues. They would need to be mounted in a way that allows for elevation and traverse of the weapon to track the wyvern. They are also rather expensive and large pieces and only one, maybe two could be mounted on a ship, especially if that ship is supposed to be a merchant vessel. Additionally the sails would get in the way of aiming and aiming itself will not be easy.
Perhaps it would make more sense for the city to field a number of small vessels built solely for the purpose of protecting other vessels from wyvern attacks. These ships would escort other vessels accross the bay and return to port afterwards. That could allow more expensive solutions and dedicated designs, rather than trying to squeeze an apropriate weapon on a regular vessel. The city would likely be willing to spend a lot of money to ensure the safety of its main trade route.
This is my first question, so please let me know if information is missing or unclear or if theres otherwise something I need to add or fix. Thank you for your time.