Set a large pot over medium-high heat. Place onion and ginger cut-side down in a dry skillet or under a broiler, turning once, until charred in spots, about 5 to 8 minutes. Do not blacken completely.
In a small dry skillet, toast star anise and cinnamon for 30 to 60 seconds until fragrant. Add to a stockpot with chicken stock, charred onion, and ginger. Bring to a gentle simmer, cover partly, and cook 25 minutes.
Stir in fish sauce and sugar. Add chicken and simmer gently until the thickest part reaches 165°F, about 12 to 18 minutes depending on cut and thickness. Remove chicken and rest briefly.
Strain broth through a fine sieve and return it to the pot. Taste and adjust with a little more fish sauce or salt. Shred or thinly slice the chicken. Keep broth hot.
Prepare rice noodles according to package directions, then drain. Divide noodles and chicken among four warm bowls.
Add the bean sprouts to the simmering broth for 2 minutes, until they are fully heated and steaming hot. Ladle the hot broth and sprouts over the noodles and chicken. Top with basil, cilantro, scallions, lime, and optional chile.