Discussions

Ask a Question
Back to All

unauthorized 401

Hi ,
i have in my trial account 19 credits left. and i am trying to call an API
url = "https://api.d-id.com/talks"
I get as a response 🙅‍♂️

Response Status: 401
Response Data: {"message":"Unauthorized"}


i am using a newly genrated api key by your APi generator.

It the issue telated to insuffiscient Credits to to this simple call ?


Thanks in Advance


i

here is my script to call the api

import requests
import json
import os
from dotenv import load_dotenv

Load environment variables from .env file

load_dotenv()


print("DID_API_KEY:", os.getenv("DID_API_KEY"))
print("ELEVEN_LABS_API_KEY:", os.getenv("ELEVEN_LABS_API_KEY"))

... existing code ...

D-ID API endpoint for creating a talk

url = "https://api.d-id.com/talks"

Use the base64 string obtained from test_image_base64.py

base64_image = "data:image/jpeg;base64,122802"

Headers with your D-ID API key and ElevenLabs TTS key

headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.getenv('DID_API_KEY')}", # Use D-ID API key from .env
"x-api-key-external": json.dumps({"elevenlabs": os.getenv("ELEVEN_LABS_API_KEY")}) # Use ElevenLabs API key from .env
}

Body parameters for the request

payload = {
"source_url": base64_image, # Use base64-encoded image string here
"script": {
"type": "text",
"input": "Testing video creation with D-ID.",
"provider": {
"type": "elevenlabs",
"voice_id": os.getenv("VOICE_ID") # Use voice ID from .env
},
"subtitles": False
},
"voice_config": {
"model_id": "eleven_multilingual_v2"
},
"persist": True
}

Make the API request

response = requests.post(url, headers=headers, data=json.dumps(payload))

Print the response status and details

print("Response Status:", response.status_code)
print("Response Data:", response.json() if response.status_code == 201 else response.text)