Skip to content

[Bug]: failed to upload files with Azure OpenAI #465

Closed
@chris-lee-lb

Description

@chris-lee-lb

Description

Currently can not upload files with Azure OpenAI successfully. Will receive this error messages.

{
  "error": {
    "code": "invalidPayload",
    "message": "purpose contains an invalid purpose."
  }
}

Steps To Reproduce

<?php

$client = OpenAI::factory()
    ->withBaseUri('<azure_openai_endpoint>')
    ->withHttpHeader('api-key', '<azure_openai_api_key>')
    ->withQueryParam('api-version', '2024-05-01-preview')
    ->withHttpClient(new \GuzzleHttp\Client(['timeout' => 60]))
    ->make();

$client->files()->upload([
    'file'    => fopen('<file_path>', 'r'),
    'purpose' => 'assistants',
]);

OpenAI PHP Client Version

v0.10.1

PHP Version

8.3.10

Notes

After further root cause analysis, it was discovered that the issue was due to the Azure OpenAI API Server being unable to correctly parse the content-length in the multipart/form-data request body sent by the OpenAI HTTP client (came from this class - Http\Message\MultipartStream\MultipartStreamBuilder). Once this content-length is removed, the upload works as expected. Currently, there is a related pull request (guzzle/psr7#581) for the GuzzleHttp Client that is awaiting merge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions