update agi function to API request