Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Vercel SDK is a type-safe Typescript SDK that gives you access to the Vercel REST API.

License

NotificationsYou must be signed in to change notification settings

speakeasy-sdks/vercel-typescript

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vercel

Develop. Preview. Ship.

Join the Vercel Community

@vercel/sdk

The@vercel/sdk is a type-safe Typescript SDK that gives you full control over the entire Vercel platform through theVercel REST API.

Table of Contents

SDK Installation

The SDK can be installed with eithernpm,pnpm,bun oryarn package managers.

NPM

npm add @vercel/sdk

PNPM

pnpm add @vercel/sdk

Bun

bun add @vercel/sdk

Yarn

yarn add @vercel/sdk

Note

This package is published as an ES Module (ESM) only. For applications usingCommonJS, useawait import("@vercel/sdk") to import and use this package.

Model Context Protocol (MCP) Server

This SDK is also an installable MCP server where the various SDK methods areexposed as tools that can be invoked by AI applications.

Node.js v20 or greater is required to run the MCP server from npm.

Claude installation steps

Add the following server definition to yourclaude_desktop_config.json file:

{"mcpServers": {"Vercel": {"command":"npx","args": ["-y","--package","@vercel/sdk","--","mcp","start","--bearer-token","..."      ]    }  }}
Cursor installation steps

Create a.cursor/mcp.json file in your project root with the following content:

{"mcpServers": {"Vercel": {"command":"npx","args": ["-y","--package","@vercel/sdk","--","mcp","start","--bearer-token","..."      ]    }  }}

You can also run MCP servers as a standalone binary with no additional dependencies. You must pull these binaries from available Github releases:

curl -L -o mcp-server \    https://github.com/{org}/{repo}/releases/download/{tag}/mcp-server-bun-darwin-arm64&& \chmod +x mcp-server

If the repo is a private repo you must add your Github PAT to download a release-H "Authorization: Bearer {GITHUB_PAT}".

{"mcpServers": {"Todos": {"command":"./DOWNLOAD/PATH/mcp-server","args": ["start"      ]    }  }}

For a full list of server arguments, run:

npx -y --package @vercel/sdk -- mcp start --help

Requirements

For supported JavaScript runtimes, please consultRUNTIMES.md.

Access Tokens

You need to pass a valid access token to be able to use any resource or operation. Refer toCreating an Access Token to learn how to create one. Make sure that you create a token with the correct Vercelscope.If you face permission (403) errors when you are already sending a token, it can be one of the following problems:

  • The token you are using has expired. Check the expiry date of the token in the Vercel dashboard.
  • The token does not have access to the correct scope, either not the right team or it does not have account level access.
  • The resource or operation you are trying to use is not available for that team. For example, AccessGroups is an Enterprise only feature and you are using a token for a team on the pro plan.

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

NameTypeScheme
bearerTokenhttpHTTP Bearer

To authenticate with the API thebearerToken parameter must be set when initializing the SDK client instance. For example:

import{Vercel}from"@vercel/sdk";constvercel=newVercel({bearerToken:"<YOUR_BEARER_TOKEN_HERE>",});asyncfunctionrun(){constresult=awaitvercel.accessGroups.readAccessGroup({idOrName:"ag_1a2b3c4d5e6f7g8h9i0j",teamId:"team_1a2b3c4d5e6f7g8h9i0j1k2l",slug:"my-team-url-slug",});console.log(result);}run();

SDK Example Usage

List deployments

List deployments under the authenticated user or team.

import{Vercel}from"@vercel/sdk";constvercel=newVercel({bearerToken:"<YOUR_BEARER_TOKEN_HERE>",});asyncfunctionrun(){constresult=awaitvercel.deployments.getDeployments({app:"docs",from:1612948664566,limit:10,projectId:"QmXGTs7mvAMMC7WW5ebrM33qKG32QK3h4vmQMjmY",projectIds:["prj_123","prj_456",],target:"production",to:1612948664566,users:"kr1PsOIzqEL5Xg6M4VZcZosf,K4amb7K9dAt5R2vBJWF32bmY",since:1540095775941,until:1540095775951,state:"BUILDING,READY",teamId:"team_1a2b3c4d5e6f7g8h9i0j1k2l",slug:"my-team-url-slug",});console.log(result);}run();

Update an existing project

Update the fields of a project using either its name or id.

import{Vercel}from"@vercel/sdk";constvercel=newVercel({bearerToken:"<YOUR_BEARER_TOKEN_HERE>",});asyncfunctionrun(){constresult=awaitvercel.projects.updateProject({idOrName:"prj_12HKQaOmR5t5Uy6vdcQsNIiZgHGB",teamId:"team_1a2b3c4d5e6f7g8h9i0j1k2l",slug:"my-team-url-slug",requestBody:{name:"a-project-name",},});console.log(result);}run();

Available Resources and Operations

Available methods

Standalone functions

All the methods listed above are available as standalone functions. Thesefunctions are ideal for use in applications running in the browser, serverlessruntimes or other environments where application bundle size is a primaryconcern. When using a bundler to build your application, all unusedfunctionality will be either excluded from the final bundle or tree-shaken away.

To read more about standalone functions, checkFUNCTIONS.md.

Available standalone functions

File uploads

Certain SDK methods accept files as part of a multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.

Tip

Depending on your JavaScript runtime, there are convenient utilities that return a handle to a file without reading the entire contents into memory:

  • Node.js v20+: Since v20, Node.js comes with a nativeopenAsBlob function innode:fs.
  • Bun: The nativeBun.file function produces a file handle that can be used for streaming file uploads.
  • Browsers: All supported browsers return an instance to aFile when reading the value from an<input type="file"> element.
  • Node.js v18: A file stream can be created using thefileFrom helper fromfetch-blob/from.js.
import{Vercel}from"@vercel/sdk";import{openAsBlob}from"node:fs";constvercel=newVercel({bearerToken:"<YOUR_BEARER_TOKEN_HERE>",});asyncfunctionrun(){constresult=awaitvercel.artifacts.uploadArtifact({contentLength:3848.22,xArtifactDuration:400,xArtifactClientCi:"VERCEL",xArtifactClientInteractive:0,xArtifactTag:"Tc0BmHvJYMIYJ62/zx87YqO0Flxk+5Ovip25NY825CQ=",hash:"12HKQaOmR5t5Uy6vdcQsNIiZgHGB",teamId:"team_1a2b3c4d5e6f7g8h9i0j1k2l",slug:"my-team-url-slug",requestBody:awaitopenAsBlob("example.file"),});console.log(result);}run();

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:

import{Vercel}from"@vercel/sdk";constvercel=newVercel({bearerToken:"<YOUR_BEARER_TOKEN_HERE>",});asyncfunctionrun(){constresult=awaitvercel.accessGroups.readAccessGroup({idOrName:"ag_1a2b3c4d5e6f7g8h9i0j",teamId:"team_1a2b3c4d5e6f7g8h9i0j1k2l",slug:"my-team-url-slug",},{retries:{strategy:"backoff",backoff:{initialInterval:1,maxInterval:50,exponent:1.1,maxElapsedTime:100,},retryConnectionErrors:false,},});console.log(result);}run();

If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:

import{Vercel}from"@vercel/sdk";constvercel=newVercel({retryConfig:{strategy:"backoff",backoff:{initialInterval:1,maxInterval:50,exponent:1.1,maxElapsedTime:100,},retryConnectionErrors:false,},bearerToken:"<YOUR_BEARER_TOKEN_HERE>",});asyncfunctionrun(){constresult=awaitvercel.accessGroups.readAccessGroup({idOrName:"ag_1a2b3c4d5e6f7g8h9i0j",teamId:"team_1a2b3c4d5e6f7g8h9i0j1k2l",slug:"my-team-url-slug",});console.log(result);}run();

Error Handling

VercelError is the base class for all HTTP error responses. It has the following properties:

PropertyTypeDescription
error.messagestringError message
error.statusCodenumberHTTP response status code eg404
error.headersHeadersHTTP response headers
error.bodystringHTTP body. Can be empty string if no body is returned.
error.rawResponseResponseRaw HTTP response
error.data$Optional. Some errors may contain structured data.See Error Classes.

Example

import{Vercel}from"@vercel/sdk";import{VercelBadRequestError}from"@vercel/sdk/models/vercelbadrequesterror.js";import{VercelError}from"@vercel/sdk/models/vercelerror.js.js";constvercel=newVercel({bearerToken:"<YOUR_BEARER_TOKEN_HERE>",});asyncfunctionrun(){try{constresult=awaitvercel.accessGroups.readAccessGroup({idOrName:"ag_1a2b3c4d5e6f7g8h9i0j",teamId:"team_1a2b3c4d5e6f7g8h9i0j1k2l",slug:"my-team-url-slug",});console.log(result);}catch(error){// The base class for HTTP error responsesif(errorinstanceofVercelError){console.log(error.message);console.log(error.statusCode);console.log(error.body);console.log(error.headers);// Depending on the method different errors may be thrownif(errorinstanceofVercelBadRequestError){console.log(error.data$.error);// models.ErrorT}}}}run();

Error Classes

Primary errors:

Less common errors (8)

Network errors:

Inherit fromVercelError:

  • VercelNotFoundError: Status code404. Applicable to 112 of 180 methods.*
  • VercelRateLimitError: . Status code429. Applicable to 5 of 180 methods.*
  • ResponseValidationError: Type mismatch between the data returned from the server and the structure expected by the SDK. Seeerror.rawValue for the raw value anderror.pretty() for a nicely formatted multi-line string.

* Checkthe method documentation to see if the error is applicable.

Server Selection

Override Server URL Per-Client

The default server can be overridden globally by passing a URL to theserverURL: string optional parameter when initializing the SDK client instance. For example:

import{Vercel}from"@vercel/sdk";constvercel=newVercel({serverURL:"https://api.vercel.com",bearerToken:"<YOUR_BEARER_TOKEN_HERE>",});asyncfunctionrun(){constresult=awaitvercel.accessGroups.readAccessGroup({idOrName:"ag_1a2b3c4d5e6f7g8h9i0j",teamId:"team_1a2b3c4d5e6f7g8h9i0j1k2l",slug:"my-team-url-slug",});console.log(result);}run();

Custom HTTP Client

The TypeScript SDK makes API calls using anHTTPClient that wraps the nativeFetch API. Thisclient is a thin wrapper aroundfetch and provides the ability to attach hooksaround the request lifecycle that can be used to modify the request or handleerrors and response.

TheHTTPClient constructor takes an optionalfetcher argument that can beused to integrate a third-party HTTP client or when writing tests to mock outthe HTTP client and feed in fixtures.

The following example shows how to use the"beforeRequest" hook to to add acustom header and a timeout to requests and how to use the"requestError" hookto log errors:

import{Vercel}from"@vercel/sdk";import{HTTPClient}from"@vercel/sdk/lib/http";consthttpClient=newHTTPClient({// fetcher takes a function that has the same signature as native `fetch`.fetcher:(request)=>{returnfetch(request);}});httpClient.addHook("beforeRequest",(request)=>{constnextRequest=newRequest(request,{signal:request.signal||AbortSignal.timeout(5000)});nextRequest.headers.set("x-custom-header","custom value");returnnextRequest;});httpClient.addHook("requestError",(error,request)=>{console.group("Request Error");console.log("Reason:",`${error}`);console.log("Endpoint:",`${request.method}${request.url}`);console.groupEnd();});constsdk=newVercel({httpClient:httpClient});

Debugging

You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass a logger that matchesconsole's interface as an SDK option.

Warning

Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.

import{Vercel}from"@vercel/sdk";constsdk=newVercel({debugLogger:console});

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usageto a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionallylooking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

SDK Created bySpeakeasy

About

Vercel SDK is a type-safe Typescript SDK that gives you access to the Vercel REST API.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript100.0%

[8]ページ先頭

©2009-2025 Movatter.jp