Move the check for beta earlier in the code so that the agent string includes the API.