- Embed interactive maps with Mapbox GL JS using a public token
- Geocode addresses and search places with the Geocoding API
- Calculate routes and turn-by-turn directions
- Render static map images for previews and thumbnails
Common use cases and example apps
How to connect Mapbox
Who can create Mapbox connections depends on your plan and workspace settings. See Who can create connections. You can create multiple Mapbox connections using different tokens, which is useful for separating environments (for example, development and production) or using different Mapbox accounts. When the connection is created, you can link it to the projects where you want to use it. Anyone building in a project can ask Lovable in chat to link their project to it.Prerequisites
Before connecting Mapbox, make sure you have:- A Mapbox account
- At least one Mapbox access token: a public token (
pk.) for browser maps, a secret token (sk.) for server-side APIs, or both - Permission to create connections in your Lovable workspace (see Who can create connections)
All Mapbox API usage counts toward your Mapbox plan and is billed by Mapbox, not Lovable.
Step 1: Get Mapbox access tokens
Mapbox uses two token types for different surfaces. They are not interchangeable.- Public token (
pk.): browser only. Use it for Mapbox GL JS and map tiles in the frontend. - Secret token (
sk.): backend only. Use it for geocoding, directions, static images, and every other server-side Mapbox API called through Lovable’s connector gateway.
1
Open your Mapbox account
Sign in to Mapbox.
2
Open access tokens
Go to Access tokens.
3
Create or copy tokens
Create the tokens your app needs:
- Public token: create or copy a default public token that starts with
pk.. Restrict it to your app domains when you go to production. - Secret token (if you need geocoding, directions, or other server-side APIs): click Create a token, give it a descriptive name (for example,
Lovable integration), choose the scopes your app needs, and copy the token that starts withsk..
4
Store the tokens securely
Copy each token and store it securely. You’ll paste them into Lovable in the next step.
Step 2: Connect Mapbox to Lovable
You can create multiple connections using different tokens.1
Open Mapbox in Connectors
Go to Connectors → App connectors and select Mapbox.
2
Add a connection
Click Add connection.
3
Configure the connection
- Display name: name the connection, for example
Mapbox Prod. This name is only used inside Lovable to identify the connection. - Secret token (optional): paste your secret token (
sk.) if your app needs server-side geocoding, directions, static images, or other backend Mapbox APIs. - Public token (optional): paste your public token (
pk.) if your app renders Mapbox GL JS maps in the browser. This value is publicly visible in your published app after you link the connection to a project.
4
Choose who can use this connection
Under Who can use this connection, decide who in your workspace can use the connection. You start as the only person with access:
- Only you (default): leave the access list as is; only you can use the connection and its associated data.
- Invite specific people: add workspace members by email; only you and the people you add can use the connection and its associated data.
- Invite entire workspace: click Invite entire workspace to make the connection available to everyone in your Lovable workspace.
5
Connect
Click Connect. Lovable validates each token you provide against Mapbox before saving the connection.
Public and secret tokens
The connector accepts two tokens with different roles:- The secret token (
sk.) is used for server-side Mapbox API calls. Lovable routes these requests through the connector gateway and exposes the token to your backend asMAPBOX_API_KEYafter you link the connection to a project. Never use the secret token in frontend code. - The public token (
pk.) is used for Mapbox GL JS in the browser. After you link the connection, Lovable exposes it asVITE_LOVABLE_CONNECTOR_MAPBOX_PUBLIC_TOKEN. Restrict this token to your app domains in the Mapbox account dashboard.
https://api.mapbox.com directly from backend code in generated apps.
Limitations
The Mapbox connector cannot:- Use a public token (
pk.) for server-side Mapbox API calls or through the connector gateway - Use a secret token (
sk.) in frontend code or Mapbox GL JS - Replace domain restrictions on your public token. You must configure allowed URLs in the Mapbox account dashboard for production domains
- Support per-end-user Mapbox authentication. Each connection represents a single Mapbox account shared across all projects linked to it
- Refresh or rotate tokens automatically. To rotate, create new tokens in Mapbox and update the Lovable connection
How to unlink projects from a connection
Editors and above can remove specific projects from a connection without deleting the connection entirely. The connection will remain available for other projects. To unlink projects:1
Open Connectors
Open Connectors, then go to App connectors, and select .
2
Open the connection
Open the connection you want to manage.
3
Select projects
Under Linked projects, check the projects you want to unlink.
4
Confirm
Click Unlink projects and confirm.
How to delete a connection
Workspace admins and owners can delete connections. Other members can delete a connection if they created it, or if they have been explicitly granted access to it. Before deleting, review the Linked projects section to see which projects are currently using the connection. To delete a connection:1
Open Connectors
Open Connectors, then go to App connectors, and select .
2
Open the connection
Open the connection you want to remove.
3
Review linked projects
Review the Linked projects section.
4
Delete
Under Delete this connection, click Delete and confirm.