Skip to content

Sora 2 video create fails with bad request #640

@artemptushkin

Description

@artemptushkin

Given:

@SpringBootTest
@ActiveProfiles("integration-test")
class SoraStrategyTest {
    val path = Path("/my/path/bear.jpeg")

    @Autowired
    lateinit var openAiClient: OpenAIClient

    @Test
    fun testIt() {
        val prompt = "bear is cooking a fish"
        openAiClient.videos().create(
            VideoCreateParams.builder()
                .model(VideoModel.SORA_2)
                .prompt(prompt)
                .seconds(VideoSeconds.of("4"))
                .let { builder ->
                    path.let {
                        builder
                            .inputReference(MultipartField.builder<InputStream>()
                                .value(it.inputStream())
                                .contentType("image/jpeg")
                                .build())
                    }
                }
                .size(VideoSize._720X1280)
                .build()
        )
    }
}

It fails with

com.openai.errors.BadRequestException: 400: Invalid type for 'input_reference': expected a file, but got a string instead.

I tried many options... need a clue please


It works like this in raw

@Test
    fun testRaw() {
        val prompt = "bear is cooking a fish"

        val r = generateVideo(prompt, path.inputStream())
        println(r.code)
        println(r.body?.string())
    }

    fun generateVideo(prompt: String, imageStream: InputStream): Response {
        val client = OkHttpClient()

        val body = MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("prompt", prompt)
            .addFormDataPart("model", "sora-2")
            .addFormDataPart("size", "720x1280")
            .addFormDataPart(
                "input_reference",
                "image.jpg",
                RequestBody.create("image/jpeg".toMediaTypeOrNull()!!, imageStream.readBytes())
            )
            .build()

        val request = Request.Builder()
            .url("https://api.openai.com/v1/videos")
            .post(body)
            .addHeader("Authorization", "Bearer ...")
            .build()

        return client.newCall(request).execute()
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedsdk

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions