Blueprint endpoints
Endpoints turn your Python functions into API endpoints to form a serverless backend for your applications. You can build and test endpoints from the web IDE.
The @route decorator
The @route
decorator transforms a Python function in Blueprint into an endpoint.
route
route(
path: str,
is_public: bool = False,
allowed_domains: List[str] = [],
allowed_methods: List[str] = ["GET"],
)
Decorator: transform a Python function in Blueprint into an endpoint.
Example:
@route(
path="/public-route",
is_public=True,
allowed_domains=["https://example.com", "https://another-example.com"],
allowed_methods=["GET", "POST"]
)
def my_route(request):
...
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to use for the route |
required |
is_public |
bool
|
is this a public endpoint? (Public endpoints do not require an API key to request.) |
False
|
allowed_domains |
List[str]
|
Allowed domains prevent CORS issues when invoking public endpoints. |
[]
|
allowed_methods |
List[str]
|
Choose to support |
['GET']
|
Info
Routes' pathes must start with /
. The root route (just /
) is not supported, the path must be /something
.
Invoking endpoints
You can invoke endpoints from the Blueprint web IDE or anywhere that can send an HTTP request: terminal, code, testing tools like Postman, and applications.
The url to invoke is formatted as follows:
Authentication
Requests to private endpoints (by default, endpoints are private) must be accompanied with an API key for authentication.
Pass the API key with an authorization header in the HTTP request. In cURL, that looks like:
Input Format
Your Python function should accept a single positional argument, request
, which passes in a dictionary of input. Input includes HTTP method, headers (all request headers are passed to the function), and body (for non-GET methods).
Blueprint endpoints support GET, POST, PUT, and DELETE methods. For GET and DELETE requests, you can pass data with query parameters. For POST and PUT, use the HTTP request body.
Example POST requests:
Form parameters:
curl -X POST https://app.baseten.co/routes/PROJECT_ID/invoke-whisper \
-H 'Authorization: Api-Key YOUR_API_KEY' \
-d 'url=https://cdn.baseten.co/docs/production/Gettysburg.mp3'
JSON:
curl -X POST https://app.baseten.co/routes/PROJECT_ID/invoke-whisper \
-H 'Content-Type: application/json' \
-H 'Authorization: Api-Key YOUR_API_KEY' \
-d '{"url": "https://cdn.baseten.co/docs/production/Gettysburg.mp3"}'
Output format
Your Python function can output anything JSON-serializable. Blueprint will serialize it and wrap it in a dictionary with the following format:
You do not need to return success: true
from your function, Blueprint does that for you. The endpoint will return success: false
in the error case.
Note that for now, functions always return a 200
HTTP code, even in error cases. Proper HTTP codes will be added in the future.