The increasing reliance on machine-generated text across various applications has highlighted the importance of ensuring high-quality outputs that are both coherent and contextually accurate. Conventional approaches to prompt engineering often involve manual tuning, which introduces limitations in scalability and consistency, particularly for tasks that demand real-time responsiveness. A novel token-level-guided automatic prompt optimization (TAPO) framework has been developed to address these challenges, offering an adaptive mechanism that refines prompts through real-time feedback at the token level. Through its integration with the Mistral model, the framework significantly improves fluency, coherence, and factual accuracy across a range of text generation tasks. The results demonstrate that the TAPO framework outperforms human-designed prompts by dynamically adjusting token probabilities, providing a more efficient and scalable solution for high-quality text generation. This contribution opens new possibilities for fully automated prompt optimization in LLMs, reducing human intervention while maintaining the adaptability required for complex language tasks.