Hey everyone — I’m brand new to TouchDesigner (using version 2023.12230), and I’m trying to connect it to both Stability AI and Replicate to generate images using SDXL Turbo.
I’m setting the Authorization header in the Web Client DAT as "Bearer <my_api_key>" and the Content-Type as application/json. The request is being prepared using Python callbacks like onRequestPrepare, and everything seems right… but I keep getting 401 Unauthorized errors from both APIs.
Weirdly, the same API keys work fine in Postman and Python outside of TD. So I’m wondering if TouchDesigner isn’t passing headers correctly, or if something subtle is off with how I’m constructing the request.
Has anyone else run into this or figured out what’s needed to make authenticated requests work in TD? I’m just getting started and would love any pointers.
can you share all the parameters of your Web Client DAT? Is the Request Method set to what the API requires and how did you set up the Authentication on the DAT itself?
Also not sure where the onRequestPrepare callback comes from?
I’m attaching the .toe file and the screenshots here. Just a heads-up — I’m very new to TouchDesigner (my background is more in game engines), so apologies if I’ve missed anything obvious. I also tried using replicate apis and got the same error but im AFK from my desktop which has that version
the Web Client DAT can take 2 inputs which are usually Table DATs, the first input specifying name/value pairs for the header and the second input specifying name/value pairs for the data.
Looking at the API for Stability AI, your header table should specify the authorization and API key while the second input table would specify the prompt.
Theoretically, this should already work:
But I’m saying theoretically as we found that you cannot currently post form data and have it encoded as multipart and the API will return this error message:
{"errors":["content-type: must be multipart/form-data"],"id":"3ba24578669c55f701543b92500aae1d","name":"bad_request"}
So unfortunately right now you would have to use python’s requests library to communicate with stability ai.