Calling API with external_id reply

Is it possible to use the external_id from SSO to call the API to reply to posts, in order to avoid having to determine the user’s username via external_id every time?

No, that is not possible.

You don’t have to determine it “every time” though, you could decide to cache it on the calling side.

If User A changes their name via Discourse, and at the same time User B also changes their name to User A’s previous name, is it possible that retrieving User A’s name from the cache could result in User A’s replies being associated with User B?

Yes, although that sounds a bit theoretical, it is certainly possible. It would be better if one could authenticate against a user ID.

Set a webhook on user.updated to flush your cache for that user!

Yes, this should be a relatively good solution. Thank you.
However, is it still possible that the webhook drops packets due to network fluctuations, causing the cache not to refresh?
Although this can be solved to some extent through cache TTL, problems may still occur before the TTL cache expires.
Finally, the safest way is to obtain the accurate username through external_id.
Of course, these are just my personal theoretical guesses.