Skip to content

[InferenceClient] Provide a way to deal with content-type header when sending raw bytes #2706

Closed
@Wauplin

Description

@Wauplin

First reported by @freddyaboulton on slack (private).

For some tasks (e.g. automatic-speech-recognition) we are sending raw bytes in the HTTP request. On InferenceAPI, there is a "content-type-guess" logic to implicitly interpret the data that is sent. However, this logic can be flawed and moreover, the Inference Endpoints don't have this logic.

It currently possible to provide the Content-Type headers by providing a value when initializing the InferenceClient :

client = InferenceClient(url, headers={"Content-Type": "audio/mpeg"})
response = client.automatic_speech_recognition("audio.mp3")

However this is not well documented + it doesn't feel correct to initialize a client with a specific content type (it would mean that all requests made with the client have to send the same content type).


Opening the issue here but not clear to me what we'd like to do. A few solutions could be:

  • (low hanging fruit) keep what we have but document how to set content-type headers in each method docstring
  • infer the content type header based on file extension (but don't work if raw bytes are passed to the method)
  • add a parameter? (but how would it work with auto-generation?)

Open to suggestions on this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions