Tesla Fleet token error
The problem
Hi,
I followed the steps outlined on the integration website on Home Assistant.
I generated a private key that I placed within /config, named tesla_fleet.key.
I then set up a page that is named https://carkey.<my-domain>.no/.well-known/appspecific/com.tesla.3p.public-key.pem hosted with Cloudflare Pages. I've made sure that this page is accessible through a curl request outside my own network.
I then registered the app at Tesla's webpages and set https://carkey.<my-domain>.no as the origin with https://my.home-assistant.io/redirect/oauth as the redirect URL.
I then sent the following curl request to Tesla:
CLIENT_ID="<client-id>"
CLIENT_SECRET='<client-secret>'
AUDIENCE='https://fleet-api.prd.eu.vn.cloud.tesla.com'
curl --request POST \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode "client_id=$CLIENT_ID" \
--data-urlencode "client_secret=$CLIENT_SECRET" \
--data-urlencode 'scope=openid offline_access vehicle_device_data vehicle_location vehicle_cmds vehicle_charging_cmds energy_device_data energy_cmds' \
--data-urlencode "audience=$AUDIENCE" \
'https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/v3/token'
This gave me an Auth token, which I then used in the next curl request:
ACCESS_TOKEN="<token>"
YOUR_DOMAIN="carkey.<my-domain>.no"
curl --location 'https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/partner_accounts' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--data '{
"domain": "'"$YOUR_DOMAIN"'"
}'
That gave me the following:
{
"response": {
"account_id":"<id>",
"domain":"carkey.<my-domain>.no",
"name":"Home Assistant",
"description":"An API app for Home Assistant",
"client_id":"<client-id>",
"ca":null,
"created_at":"2025-04-24T19:08:32.349Z",
"updated_at":"2025-04-24T20:07:07.524Z",
"enterprise_tier":"pay_as_you_go",
"issuer":null,
"csr":null,
"csr_updated_at":null,
"public_key":"<not-my-public-key>",
"public_key_hash":"<hash>"
}
}
I saw somewhere that you can check that your partner account is working using the following url:
https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/partner_accounts/public_key?domain=carkey.<my-domain>.no
This however didn't work for me, so I'm unsure if that was a sign one of the steps above didn't work, or if something else was at fault.
Anyway, I then tried to add the integration to Home Assistant, I set the name, client id, and client secret to match my application at Tesla Developer. I then sign into my account, checked all the boxes for the scope and after a short period of time I get the error Error while obtaining access token
I checked the logs, which showed me the following:
2025-04-24 22:44:59.529 INFO (MainThread) [homeassistant.components.tesla_fleet] Successfully authenticated
2025-04-24 22:44:59.729 WARNING (MainThread) [homeassistant.components.tesla_fleet] Region is invalid, trying to find the correct region
2025-04-24 22:45:00.664 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Token request for tesla_fleet_<cliend-id> failed (invalid_auth_code): The authorization code is invalid. It may have already been used or expired. Request a new sign in session to generate a new code.
2025-04-24 22:45:00.664 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Error resolving OAuth token: 400, message='Bad Request', url='https://auth.tesla.com/oauth2/v3/token'
I'm probably making a simple mistake somewhere, but I really can't find it for the life of me.
I appreciate all help resolving this, as I'd like to set up an automation for charging at specific times to save money :D
Thank you for taking your time to read though!
What version of Home Assistant Core has the issue?
core-2025.4.3
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Tesla Fleet
Link to integration documentation on our website
https://www.home-assistant.io/integrations/tesla_fleet
Diagnostics information
No response
Example YAML snippet
Anything in the logs that might be useful for us?
Additional information
No response
Hey there @bre77, mind taking a look at this issue as it has been labeled with an integration (tesla_fleet) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of tesla_fleet can trigger bot actions by commenting:
@home-assistant closeCloses the issue.@home-assistant rename Awesome new titleRenames the issue.@home-assistant reopenReopen the issue.@home-assistant unassign tesla_fleetRemoves the current integration label and assignees on the issue, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the issue.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.
(message by CodeOwnersMention)
tesla_fleet documentation tesla_fleet source (message by IssueLinks)
I'd repeat the registration setup again but for North America too, your error had something about a region mismatch.
https://fleet-api.prd.na.vn.cloud.tesla.com/api/1/partner_accounts instead of https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/partner_accounts
Also make sure that curl command is a POST
Thanks, you're right!
Using the US url instead of the European worked instantly. It might be worth updating the following section in the documentation:
Register your application as a Fleet API partner
Replace the AUDIENCE value with your region-specific URL. The URL in the example is for users in North America and Asia-Pacific (excluding China). Refer to the Base URLs documentation for the URLs for other regions.
PS. Thanks for the really swift reply too!
Ran in the same issue when installing Tesla fleet integration and following the docs (based in EU so I used the URL for EU instead of NA). Workaround to use the NA URL worked fine. I agree the docs should be updated.
Works with the EU too, after approving your key at https://tesla.com/_ak/YOUR_DOMAIN using your phone app.
Hi @Bre77,
Not sure where to post this but the UI of the Tesla Fleet intergration sends me to https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/... rather than the eu version. Resulting in a “An unknown error occurred: There is a semantic problem with the data, e.g. missing or invalid data.”
Could you help me with this please?
Hi @Bre77,
Not sure where to post this but the UI of the Tesla Fleet intergration sends me to https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/... rather than the eu version. Resulting in a “An unknown error occurred: There is a semantic problem with the data, e.g. missing or invalid data.”
Could you help me with this please?
You should post this to a new issue so it can be addressed separately.
That url is not NA or EU, but also you should be redirected to auth.tesla.com
I followed the guide, also tried to start from scratch but I'm still getting this error in homeassist dialog window (after redirects: tesla-my.home-assistant.io-MyHostedHomeassist):
Registering public key
You must host the public key at:
https://mysite/.well-known/appspecific/com.tesla.3p.public-key.pem
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZI..............Fm9Eq5G8j1g==
-----END PUBLIC KEY-----
Error:
**The public key hosted at your domain does not match the expected key. Please ensure the correct public key is hosted at the specified location.**
api/1/partner_accounts/public_key?domain=... confirm my partner works fine. I don't see any errors in homeassist logs. Any thoughts?
Solved. For some reason I had to copy public key that homeassist show me from dialog window and replace with one I host on my website. ...then go to my car, unlock it with app, then open link https://www.tesla.com/_ak/...mysite.. and allow adding a key. Works now.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.