Skip to content

400 Bad Request and Invalid type for instructions #134

@stanstrup

Description

@stanstrup

I don't understand enough to be helpful about what the problem is but this is what I get when I try to convert an epub with openAI.

D:\Downloads>docker run -i -t --rm -v D:/Downloads/:/app -e OPENAI_API_KEY=NOOOOO ghcr.io/p0n1/epub_to_audiobook "my.epub" audiobook_output --tts openai
Starting entrypoint script...
Executing default command: python3 /app_src/main.py richter.epub audiobook_output --tts openai
/usr/local/lib/python3.11/site-packages/ebooklib/epub.py:1423: FutureWarning: This search incorrectly ignores the root element, and will be fixed in a future version.  If you rely on the current behaviour, change it to './/xmlns:rootfile[@media-type]'
  for root_file in tree.findall('//xmlns:rootfile[@media-type]', namespaces={'xmlns': NAMESPACES['CONTAINERNS']}):
2025-04-26 19:18:55,336 - audiobook_generator.py:105 - run - INFO - Chapters count: 1.
2025-04-26 19:18:55,337 - audiobook_generator.py:123 - run - INFO - Converting chapters from 1 to 1.
2025-04-26 19:18:55,337 - audiobook_generator.py:131 - run - INFO - ✨ Total characters in selected book chapters: 18437 ✨
Estimate book voiceover would cost you roughly: $0.06

Do you want to continue? (y/n)
y
2025-04-26 19:19:14,976 - [Worker-7] - audiobook_generator.py:60 - process_chapter - INFO - Processing chapter 1: NINA_LVOVNA
2025-04-26 19:19:15,214 - [Worker-7] - openai_tts_provider.py:70 - text_to_speech - INFO - Processing chapter-1_NINA_LVOVNA_chunk_1_of_11, length=1670
2025-04-26 19:19:15,936 - [Worker-7] - _client.py:1038 - _send_single_request - INFO - HTTP Request: POST https://api.openai.com/v1/audio/speech "HTTP/1.1 400 Bad Request"
2025-04-26 19:19:15,941 - [Worker-7] - audiobook_generator.py:87 - process_chapter - ERROR - Error processing chapter 1, error: Error code: 400 - {'error': {'message': "Invalid type for 'instructions': expected a string, but got null instead.", 'type': 'invalid_request_error', 'param': 'instructions', 'code': 'invalid_type'}}
Traceback (most recent call last):
  File "/app_src/audiobook_generator/core/audiobook_generator.py", line 81, in process_chapter
    tts_provider.text_to_speech(text, output_file, audio_tags)
  File "/app_src/audiobook_generator/tts_providers/openai_tts_provider.py", line 78, in text_to_speech
    response = self.client.audio.speech.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/resources/audio/speech.py", line 100, in create
    return self._post(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1242, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 919, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1023, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid type for 'instructions': expected a string, but got null instead.", 'type': 'invalid_request_error', 'param': 'instructions', 'code': 'invalid_type'}}
2025-04-26 19:19:15,966 - audiobook_generator.py:171 - run - WARNING - The following chapters failed to convert:
2025-04-26 19:19:15,967 - audiobook_generator.py:173 - run - WARNING -   - Chapter 1: NINA_LVOVNA
2025-04-26 19:19:15,967 - audiobook_generator.py:174 - run - INFO - Conversion completed with 1 failed chapters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions