Invalid API - AG8004 Even when using a valid API KEY
-
I am facing this issue where I am observing failures with below response,
They KEY is valid since I am able to login and utilize placeorder. Also this is a new key created post March 2026 to comply with sebi regulations.
Previously we had KEY TYPE which is no longer available
'message': 'Invalid API Key', 'errorCode': 'AG8004'
-
@S57010238 Since login AND placeOrder work but you still get AG8004, the key itself is fine — the failure is scoped to specific endpoints. Which call throws it (getCandleData / market data)?
Two verified findings from debugging the same error family after the April migration:
generateSessiondoesn't validate the API key at all, and endpoint groups validate scopes separately — so "logs in fine" (or even "orders work") proves nothing about the data endpoints.- The migration replaced the old KEY TYPEs (Trading / Market Feed / Historical) with unified apps, but apps or keys that straddle the migration can still be rejected on some routes. Recreating the app fresh on the new portal fixed it in my case — note you may then hit "Primary static IP is already associated with another app", because deleted legacy apps don't release their registered IPs.
Full write-up with the complete fix path + two extra gotchas (the Python SDK prints your API key into error logs; NSE Saturday DR-drill sessions serve mock candles as real data): https://smartapi.angelone.in/smartapi/forum/topic/5635/complete-fix-ag8004-invalid-api-key-after-successful-login-primary-static-ip-is-already-associated-with-another-app
If you share which endpoint fails and when the app was created, happy to help narrow it down.