Often, I can tell when an AI is about to declare on me. 1 or a couple turns before, I make a deal with that AI for (ex.) 300gold for 11gpt or something. The AI will stupidly take this deal even though it knows it will declare war on you soon. When the AI declares, your deals cancel and you get that gold practically for free with no reputation hit. Stupid AI.