Unknown API key error using nodejs api

I was using the nodejs api for alpaca for months without a problem and today I started getting “unknown api key” errors. I recreated a new pair of keys but the error remains. Anyone can help me out here?

1 Like

I’m assuming this is a Polygon issue. Alpaca discontinued its contract with Polygon over the weekend. This means your Alpaca keys no longer work to access Polygon’s endpoints.

A temporary solution is to create a Polygon account and sign up for their $199/month developer plan using the “ALPACA” coupon code for a free month.

Thanks for your reply Peter. Thats what I initially thought as well and then I have deactivated polygon in the nodejs alpaca api but I still get unknown api key response.

Are you familiar with the nodejs alpaca api?

This is how I initiate it:

	this.alpaca = new Alpaca({
		keyId: apikey,
		secretKey: apisecret,
		paper: false,
		usePolygon: false

quick update, the nodejs api hat some preserved functions that still used polygon. I changed them and got a step further but now I get an error stating “account is not authorized to trade”. Anyone know where this is coming from?

2021-03-01T18:38:03.429857+00:00 app[web.1]: error: { code: 40310000, message: ‘account is not authorized to trade’ },
2021-03-01T18:38:03.429858+00:00 app[web.1]: options: {
2021-03-01T18:38:03.429858+00:00 app[web.1]: method: ‘POST’,
2021-03-01T18:38:03.429859+00:00 app[web.1]: uri: ‘https://api.alpaca.markets/v2/orders’,
2021-03-01T18:38:03.429859+00:00 app[web.1]: qs: {},
2021-03-01T18:38:03.429859+00:00 app[web.1]: headers: {
2021-03-01T18:38:03.429860+00:00 app[web.1]: ‘content-type’: ‘application/json’,
2021-03-01T18:38:03.429860+00:00 app[web.1]: ‘APCA-API-KEY-ID’: ‘mykey’,
2021-03-01T18:38:03.429861+00:00 app[web.1]: ‘APCA-API-SECRET-KEY’: ‘mysecret’
2021-03-01T18:38:03.429861+00:00 app[web.1]: },

Glad you figured that out. Yeah, it looks like the JS API’s usePolygon parameter only dictates which websocket to use, so it doesn’t fix the issue with Polygon’s REST API.

As for “account is not authorized to trade”, I’m guessing this thread is related.

Thank you Peter, I replied into that thread asking for help. Unfortunatly, it didnt contain any fix or cause for that issue. The author just posted that it was fixed but not how. We ll see…