Hello,
Most times when the AI declares war on you it means you have low global reputation. To try to get peace with them again you could set your relation status to peace or cease fire and wait a few days the lower your global reputation the longer you have to wait, also note every time you get into combat with them the timer resets and you need to set your relation status again.
For future games to help prevent this you could set your relation status to right of way with most (or all) AI nations at the start of the game that will boost your global reputation.