API gives error randomly

v4vikash
This is the error I am getting randomly.

{"status": "error", "error_type": "TokenException", "message": "Invalid API credentials"}

What could be the possible reason?
  • sujith
    Hi @v4vikash,
    Your session might be cleared when you log into Pi or NEST. I would suggest using Kite for monitoring purpose and if you log out of Kite then you will be logged out of everywhere.
  • v4vikash
    v4vikash edited September 2017
    @sujith This does not seem correct. Primarily because it happens randomly. Some requests after this error succeed without any problem.

    Also, I have checked at Kite too - this happens even when I am logged in everywhere.
  • sujith
    Hi @v4vikash,
    Can you let us know any pattern to debug?
    Does it happen at a particular time or happens for particular API call?
  • v4vikash
    @sujith Thanks for responding fast. I am trying this API: "https://api.kite.trade/instruments/historical/"
    You can check my logs, if it is possible.

    I am also getting lots of 'Gateway timed out' error now.
  • sujith
    Hi @v4vikash,
    Gateway timeout is different from TokenException.
    TokenException means your session is expired. Gateway timeout means request timed out before fetching data.
    Historical API is used by all our platforms and Kite Connect users. There are around 50k concurrent users during market hours. Maybe you can try reducing time interval and retry.

    I would suggest handling all these errors at your end. Maybe re-login when a session is expired and retry after some delay when historical data gives the timeout.
  • v4vikash
    @sujith - Please understand that it is random. For example for multiple sequential requests: 1st request succeeds then 2nd shows TokenException then next one succeeds (without doing anything) and so on. (with gateway timeout thrown at times). It happens even during non-market hours.
  • darkknight
    @sujith Even I am facing the same issue with the historical API. Token exception: Invalid API credentials. It is currently very arbitrary. Happening even on a weekend multiple times.

    @v4vikash Do let me know if you figure out the issue here
  • sunny
    @sujith Even I am facing the same issue with the historical API. Token exception: Invalid API credentials. It is currently very arbitrary. Happening even on a weekend multiple times.
  • sujith
    Hi @sunny,
    In the recent weekends, we have been deploying new upgrades to the system. Sessions are cleared due to this. You may re-login if this happens.
This discussion has been closed.