#error 401

1 messages · Page 1 of 1 (latest)

spark widget
#

I keep getting this error and I have been trying to debug this for like 2 hours. THis is the console after I added all the debugging while trying to figure it out.

Voice generation requested for channel 1399854698349072534
Voice system available: True
Channel in enabled list: True
Generating voice for text (890 chars): She's describing ...
[DEBUG] Full API key: [removed]
[DEBUG] Key length: 67
[DEBUG] Using voice ID: b4583c6e-790d-43fa-ae06-0d8ec09c3c84
🧠 Adding to conversation memory - User: 277 chars, Bot: 876 chars
🧠 Current conversation tokens: 267/12000
🧠 Messages in buffer: 2
Cartesia response status: 401
[ERR] Cartesia API error 401: Invalid token
Cartesia returned: <class 'NoneType'> None
#

I am testing it out on the free plan.

spark widget
#

anyone out there? lol

main panther
#

Hey @spark widget - sorry idk how we missed this earlier that's our bad. What's the specific API you're trying to hit?

spark widget
# main panther Hey <@966507927756234823> - sorry idk how we missed this earlier that's our bad....

hello- thanks for replying!

API Endpoint:

POST https://api.cartesia.ai/tts/bytes

Headers Used:

Cartesia-Version: 2024-06-10
X-API-Key: [my_key]
Content-Type: application/json
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36

Request Body:

  {
    "model_id": "sonic-2",
    "transcript": "text to speak",
    "voice": {
      "mode": "id",
      "id": "b4583c6e-790d-43fa-ae06-0d8ec09c3c84"
    },
    "output_format": {
      "container": "wav",
      "encoding": "pcm_f32le",
      "sample_rate": 44100
    },
    "language": "en",
    "speed": "normal"
  }

The Issue is that the code works in the playground when i tried it out but returns 401 Invalid token when called programmatically, even though the API key is valid - i double checked it a bunch of times

main panther
#

@spark widget could you share the code snippet you're using to hit the bytes endpoint?

spark widget
# main panther <@966507927756234823> could you share the code snippet you're using to hit the b...
  async def _generate_cartesia_voice(self, text: str) -> Optional[bytes]:
      """Generate voice using Cartesia API"""
      config = self.providers['cartesia']

      headers = {
          "Cartesia-Version": "2024-06-10",
          "X-API-Key": config['api_key'],
          "Content-Type": "application/json",
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
      }

      data = {
          "model_id": "sonic-2",
          "transcript": text,
          "voice": {"mode": "id", "id": config['voice_model']},
          "output_format": {
              "container": "wav",
              "encoding": "pcm_f32le",
              "sample_rate": 44100
          },
          "language": "en",
          "speed": "normal"
      }

      try:
          async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=30)) as
  session:
              async with session.post(config['endpoint'], headers=headers, json=data) as
  response:
                  if response.status == 200:
                      audio_data = await response.read()
                      await self.log_activity("Cartesia voice generated", {'text_length':
  len(text)})
                      return audio_data
                  else:
                      error_text = await response.text()
                      self.logger.error(f"Cartesia API error {response.status}: 
  {error_text}")
                      return None

      except asyncio.TimeoutError:
          self.logger.error("Cartesia API timeout")
          return None
      except Exception as e:
          self.logger.error(f"Cartesia API exception: {e}")
          return None
spark widget
#

@main panther ?