Python
This guide shows you how to get started with FASHN's API using our official Python SDK. The SDK handles authentication, request/response parsing, error handling, and polling automatically.
For detailed documentation and how to use the FASHN API, please refer to:
Installation
First, install the FASHN Python SDK:
Generate an API Key
Go to the Developer API dashboard and click Create new API key.
You won't be able to view it again after closing the window.
Quick Start with the SDK
The SDK's subscribe
method handles the entire prediction lifecycle automatically - it submits your request, polls for completion, and returns the final result. You can use any model_name
from our API Reference section with their respective input parameters.
Synchronous
Async
Error Handling
The FASHN API has two distinct types of errors that you need to handle in different places. For a complete list of all error types and status codes, see the API Fundamentals Error Handling section.
API-Level Errors (handled in except
blocks):
- Occur before your request is accepted for processing
- Examples: invalid API key (401), rate limits (429), bad request format (400)
- Thrown as exceptions with
e.status_code
ande.message
Runtime Errors (check result.status
):
- Occur during model execution after successful request submission
- Examples: image loading failures, content moderation, pose detection issues
- Available in
result.error
fields when present
Configuration
Advanced configuration options (retries, timeouts, proxies, custom HTTP client) are available in our open source GitHub repository: fashn-python-sdk.
Advanced Usage
The SDK provides methods to submit a request and fetch the status of a request separately. If you choose this workflow you would need to:
- Submit a request
- Poll for the status of the request until it is completed
The subscribe method described above already implements this workflow with good defaults and better error handling. We only recommend using this workflow if you have a specific use case that requires it.
Submit a request
Submit a request to the API and get a prediction ID.
Fetch request status
Use the prediction ID returned from the run method to fetch the status of the request.