Before you begin
You need an active deployment, its model ID, and a Baseten API key inBASETEN_API_KEY. The deployed model defines its input format; copy the request schema from its configuration or example.
The model ID (and the deployment ID, when you need to target a specific
deployment) comes from the model’s page URL in your workspace:
Choose an interface
- OpenAI-compatible model: Use the OpenAI SDK with the routes supported by your engine or custom server.
- Custom Truss model: Send your model’s JSON input to
/predict. - Custom HTTP server: Call a route exposed by the server through
/sync.
OpenAI SDK
Use this interface for a deployment that exposes OpenAI-compatible chat, such as vLLM. Install the OpenAI SDK withpip install openai or npm install openai. Set BASETEN_MODEL_ID to your deployed model’s ID and BASETEN_SERVED_MODEL to the name accepted by its server. For vLLM, this is the value of --served-model-name in start_command.
- Python
- JavaScript
To get a chat response from your deployment:Run the following script:
model field must satisfy the server’s naming rules. Validation rules depend on the engine or server. Only call endpoints that your deployed server supports. For more information, see Streaming and the vLLM example.
Predict API endpoints
For a custom Truss model, send a JSON body that matches itspredict() method. The following request uses an identity Truss, which returns its input unchanged. Install requests with pip install requests for the Python example, and set BASETEN_MODEL_ID to your model ID.
- Python
- cURL
To send JSON to your model:Run the following script, replacing the input with your model’s expected payload:
/predict for a complete synchronous response. To queue work and receive its output later, follow Async inference.
Target an environment or deployment
The endpoint selects which version of your model receives a request:- Production:
/environments/production/predict. - Named environment:
/environments/ENVIRONMENT_NAME/predict. - Development deployment:
/development/predict. - Specific deployment:
/deployment/DEPLOYMENT_ID/predict.
Sync API endpoints
For a custom HTTP server,/sync forwards the remaining path to a route exposed by that server. For example, /environments/production/sync/health forwards to /health, while /environments/production/sync/v1/chat/completions forwards to /v1/chat/completions.
To call a custom server route:
Use the route, HTTP method, and payload defined by your server. For a server with a GET /health route that returns HTTP 200 when ready, run the following command to print its status code:
Authentication
UseAuthorization: Bearer <api_key> for dedicated deployment requests. Baseten also accepts the legacy Authorization: Api-Key <api_key> scheme, so existing scripts continue to work.
External LLM gateways
Configure the gateway with these values:- Base URL:
https://model-YOUR_MODEL_ID.api.baseten.co/environments/production/sync/v1. - Model name: The name accepted by the deployed server. For vLLM, use
--served-model-namefromstart_command. - API key: A Baseten API key with access to the deployment.
{base_url}/chat/completions with model set to the served name.
For more information, see Integrations.
Alternative invocation methods
- Baseten CLI: Send a prediction request from your terminal.
- Deployment playground: Test your model in your workspace.