⏱ Estimated Time To Completion: 3 minutes

Step 1: Sign in to Decipher

Sign in to Decipher using your work email address and a customer_id will be automatically created for you, which you’ll use in the next step.

Step 2: Integrate the SDK

Install the SDK

Terminal
pip install decipher-sdk-fastapi

Instrumenting your FastAPI app

Simply import decipher_sdk and initialize it as below.

app.py
from fastapi import FastAPI, Request
import decipher_sdk

app = FastAPI()

decipher_sdk.init(
    app,
    # A codebase name of your choice to identify errors in Decipher.
    codebase_id="CODEBASE_NAME_OF_MY_CHOICE",
    # This comes from https://www.prod.getdecipher.com/settings; see Step 1.
    customer_id="MY_CUSTOMER_ID_FROM_STEP_1"
)

@app.route("/submit", methods=['POST'])
def submit_data():
    data = request.json
    return jsonify({"status": "success", "received_data": data})

That’s it! Decipher will now monitor and surface all your errors and exceptions on the dashboard.

Capturing error details on handled exceptions

If you want to capture error details like the stack trace for handled exceptions (e.g. in a try/catch) you can use Decipher.captureError(error) like below:

app.ts
// ...other imports
import decipher_sdk

@app.get("/gonnaBeAnError")
async def create_error(request: Request):
    try:
        # Simulate an error
        raise ValueError("This is a test error")
    except Exception as e:
        # Manually capture the error
        decipher_sdk.capture_error(e)
        return {"error": "An error occurred"}

Boom! Decipher will now include the stack trace and other context to help you and Decipher’s AI debug.