depends only on A, but? not on B
Other answers explain well the redundancy of mentioning B because it and any other propositions are excluded by saying “... only on A”. But there are contextual circumstances in which it may be mentioned for reasons of style.
The conjunction but introduces a statement that limits or stands in contrast to a prior statement or proposition.
For a simple and topical example: “It has been suggested that death rate is influenced by Covid {A} and by the number of G5 masts {B}. It depends only on Covid {A} but not on a few structures standing in fields {B}”. The formally unnecessary repetition of B is used to emphasise its irrelevance.
Well . . . formally if X depends ONLY on A, any statement about B is superfluous.
But if you want to include B for emphasis either construction works, but I'd advocate for losing the comma if you include the "but".
If you are clarifying a situation with somebody who thinks X may depend on both A and B I would suggest either "X depends only on A, not on B" or "X depends on A, but not on B". Using "but" assumes there is a possibility that X might depend on B, but using "only" states there is no such possibility.