Skip to content

"Endpoint" class doesn't work as expected in new 4.1.0 version #525

Open
@ArturZhukovets

Description

@ArturZhukovets

What is the current behavior?

I'm trying to use ElevenLabs as an external speech provider. Following the documentation, I encountered an error when applying the settings.

After spending considerable time debugging, I managed to get it working—but only by patching the SDK. Below are the changes I had to make (I marked it with comments) :

@dataclass
class Endpoint(BaseResponse):
    """
    Define a custom endpoint for the agent.
    """

    method: Optional[str] = field(default="POST")  # This line seems unnecessary
    url: str = field(default="")
    headers: Optional[List[Header]] = field(
        default=None, metadata=dataclass_config(exclude=lambda f: f is None)
    )  # Using List[Header] results in incorrect JSON format. I had to replace this with Optional[dict] and define headers as raw key-value pairs.

So in summary:

  • The method field appears unused or unnecessary.

  • The headers (Header class) must be serialized correctly to JSON. Using a dictionary worked.

Here’s the working pseudo code after patching:

speak = Speak(
    provider=SpeakProvider(
        type="eleven_labs",
        model=None,
        model_id='eleven_multilingual_v2',
    ),
    endpoint=Endpoint(
        url=f'https://api.elevenlabs.io/v1/text-to-speech/{message.dev_options.voice_id}/stream',
        headers={'xi-api-key': <11labs api key>}
    )
)
  1. I removed method: Optional[str] = field(default="POST") because it was causing errors.
  2. I changed the type of the headers field to Optional[dict] so it would serialize to JSON correctly:
headers: Optional[dict] = field(
    default=None, metadata=dataclass_config(exclude=lambda f: f is None)
)

Please consider updating the SDK to handle this case properly.
Of course, it's possible I did something wrong—let me know if that's the case.

Activity

lukeocodes

lukeocodes commented on May 14, 2025

@lukeocodes
Contributor

Hi @ArturZhukovets, can you provide some more details on what you were originally trying to do. I appreciate your attempt at a workaround here but we want to avoid unions on generics in a type safe environment.

To best figure out the issue, it would really help to see your original code that was not working.

Thanks

ArturZhukovets

ArturZhukovets commented on May 15, 2025

@ArturZhukovets
Author

@lukeocodes I initially tried using the Python SDK to run an agent with an external speech provider (elenen_labs). While doing so, I encountered two issues during the serialization of dataclasses to a dictionary when preparing the settings configuration for Deepgram.

The final JSON structure ended up being invalid due to the Header class and possibly the method field. Unfortunately, I don't have the original code before my changes, but after serializing the SettingsOptions class, the result looked like this:

"speak": {
  "provider": {
    "type": "eleven_labs",
    "model_id": "eleven_multilingual_v2"
  },
  "endpoint": {
    "url": "https://api.elevenlabs.io/v1/text-to-speech/{your_agent_voiceid}/stream",
    "headers": [   // THIS IS INCORRECT
      {
        "key": "{11Labs key name}",
        "value": "{eleven_labs_api_key}"
      }
    ]
  }
}

As you can see, the headers field is not formatted correctly, which causes issues when sending the request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @lukeocodes@ArturZhukovets

      Issue actions

        "Endpoint" class doesn't work as expected in new 4.1.0 version · Issue #525 · deepgram/deepgram-python-sdk