Make Your First Vercel API Request
Use a Vercel access token to call the Vercel REST API with curl, then make the same request with @vercel/sdk. Both examples retrieve at most one project with GET /v10/projects and do not change your account.
- A Vercel account
- A terminal with
curl - An active Node.js LTS release and npm for the SDK steps
Both approaches call the same Vercel REST API operation and use the same access token:
| Approach | When to use it |
|---|---|
REST with curl | You want to call the API directly from a shell or another HTTP client. |
@vercel/sdk | You are using TypeScript or JavaScript and want generated methods and types. |
Complete both examples to confirm that your token works with direct HTTP requests and the SDK.
Go to the Account Tokens page and enter a descriptive name for the token.
Choose the narrowest scope that covers the projects you need to access with the API. The project-list operation works with Full Account, Team, and Project scopes. Then choose an expiration and select Create.
See access token scopes for the full behavior of each option.
Copy the token when Vercel displays it. You cannot view its value again after leaving the page.
In a bash or zsh terminal, run the following command. Paste the token when the terminal waits for input, then press Enter:
terminalread -s VERCEL_TOKEN && export VERCEL_TOKENThe shell does not display the token. Keep this terminal open for the remaining steps.
Send a GET request to /v10/projects. The limit=1 query parameter limits the response, and the command saves the JSON body to vercel-projects.json:
curl --fail-with-body --silent --show-error \
--output vercel-projects.json \
--write-out "HTTP %{http_code}\n" \
"https://api.vercel.com/v10/projects?limit=1" \
--header "Authorization: Bearer $VERCEL_TOKEN"A successful request prints the following status:
HTTP 200The response body can be a project array or a paginated object with projects and pagination. See the project-list response reference for every field.
Create a directory and install the Vercel SDK:
terminalmkdir vercel-api-quickstart cd vercel-api-quickstart npm init --yes npm install @vercel/sdknpm creates a
package.jsonfile and adds@vercel/sdkas a dependency.Create an
index.mjsfile with the following code:index.mjsimport { Vercel } from '@vercel/sdk'; const bearerToken = process.env.VERCEL_TOKEN; if (!bearerToken) { throw new Error('VERCEL_TOKEN is not set'); } const vercel = new Vercel({ bearerToken }); const result = await vercel.projects.getProjects({ limit: '1' }); const projects = Array.isArray(result) ? result : result.projects; if (projects.length === 0) { console.log('Success: no projects in this token scope'); } else { const project = projects[0]; console.log(`Success: ${project.name} (${project.id})`); }In TypeScript,
getProjectsreturnsPromise<GetProjectsResponseBody>. The response type can be a project array or a paginated object, so the example normalizes both forms before reading the first project.Run the script from the same terminal where you exported
VERCEL_TOKEN:terminalnode index.mjsIf the token scope contains a project, the script prints a project name and ID:
Success: my-project (prj_xxxxxxxxxxxxxxxxxxxxxxxx)If the scope contains no projects, the script still confirms that the request succeeded:
Success: no projects in this token scope
The token scope determines which projects GET /v10/projects can return:
| Token scope | Request target | teamId or slug behavior |
|---|---|---|
| Full Account | Your personal account by default, or a team you belong to | Omit both for personal projects. Pass either value to target a team. |
| Team | Projects in the token's team | Omit both. Vercel infers the team from the token. |
| Project | The token's single project | Omit both. Vercel infers the team and project from the token. |
A project-scoped token denies requests for user-level resources, team-level resources, and other projects. See access tokens for token creation and scope details.
| Status | Cause | What to check |
|---|---|---|
401 Unauthorized | The API did not accept the authentication details. | Confirm that VERCEL_TOKEN is set and the header uses Authorization: Bearer <token>. |
403 Forbidden | The token does not have permission to access the requested resource. | Check the token's expiration and scope. For a full-account token targeting a team, pass teamId or slug. |
429 Too Many Requests | A platform-wide API rate limit rejected the request. | Reduce the request rate and retry after the limit resets. |
See REST API errors for error payloads and API rate limits for limit scopes and reset behavior.
You authenticated with a Bearer token, called the read-only GET /v10/projects operation with curl, and called the same operation with vercel.projects.getProjects. You also learned how Full Account, Team, and Project token scopes affect requests.
Was this helpful?