Residual solvents are volatile organic substances, derived from synthesis or manufacturing processes, and can be present in active pharmaceutical ingredients (API). Due to their toxic potential, they must be eliminated, or at least have their content controlled according to official specifications. We aimed to optimize and validate an analytical method by gas chromatography with liquid injection to determine the residual solvents dimethylformamide (DMF) and dimethyl sulfoxide (DMSO) in the API ketoconazole. A divinylbenzene column coupled to a flame ionization detector (FID) was used and helium was chosen as the carrier gas. In selectivity there was a good separation of both peaks besides other impurities present in the sample, compared to the reference chemical substances. The method presented linearity, showing correlation coefficients of 0.99984 and 0.99976 and determination coefficients of 0.99951 and 0.999984 for DMF and DMSO, respectively. The residuals evaluation showed homoscedastic distribution and the slope met the requirements for the F test. In precision, the tested solutions revealed a relative standard deviation (RSD) value of 1.88% for DMF and 1.56% for DMSO, below the limit of 10.0%. In verifying accuracy using the recovery test, the results from 101.4 to 106.9% of the established limit, were satisfactory. Finally, robustness was assessed by means of premeditated variations of critical parameters for the method, such as sim-ultaneous changes in the column lot (+1.34% for DMF and −0.16% for DMSO) or gas flow (−1.85% for DMF and −1.52% for DMSO). Thus, the method developed is satisfactory for the purpose for which it’s intended.