Autocomplete with ajax have a bug?

I have autocomplete implemented very similar to the documentation:

var autocompleteStandalonePopup = app.autocomplete.create({
    openIn: 'popup',
    openerEl: '#autocomplete-standalone-ajax',
    closeOnSelect: true,
    valueProperty: 'id',
    textProperty: 'full_name',
    source: function (query, render) {
      var autocomplete = this;
      var results = [];
      if (query.length === 0) {
        url: baseUrl('patients'),
        method: 'GET',
        dataType: 'json',
        data: { term: query},
        crossDomain: true,
        headers: {'X-Professional-Email': getLoggedInfo('email'), 'X-Professional-Token' : getLoggedInfo('authentication_token')},
        success: function (data) {
          for (var i = 0; i < data.length; i++) {
            if (data[i].full_name.toLowerCase().indexOf(query.toLowerCase()) >= 0) { results.push(data[i]) }
    on: {
      change: function (value) {

Works well when searching for something by typing not too fast, but if I type a little faster

Api returns very fast, and I don’t believe the problem is with it.

Is there a way to solve this problem?

The problem with the API calls, just console.log of query and results. Correct solution here will be to use some debounce technic and call API within some timeout, e.g. 300ms - 500ms