-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Description
Confirm this is a Typescript library issue and not an underlying Cloudflare API issue
- This is an issue with the Typescript library
Describe the bug
When using the Cloudflare TypeScript SDK to perform a Cloudflare Vectorize upsert operation, I encounter the following error:
Error: 400 {"result":null,"success":false,"errors":[{"code":40023,"message":"vectorize.upstream_error - failed to parse upsert vectors request in ndjson format: line Some(0) was not expected format"}],"messages":[]}
This error happens when I call the client.vectorize.indexes.upsert
method. However, the same request works fine when using the fetch
method directly, with the same body and headers.
It seems that the SDK might not be properly formatting the request in the expected ndjson format.
To Reproduce
- Use the Cloudflare TypeScript SDK to perform a vectorization upsert using the
client.vectorize.indexes.upsert
method. - See the error
failed to parse upsert vectors request in ndjson format: line Some(0) was not expected format
. - Switch to using the
fetch
method with the same body and headers. - The request works as expected without the error.
Code snippets
const vectors = [
{ id: "1", values: [...], metadata: { columnId: 1 } },
{ id: "2", values: [...], metadata: { columnId: 1 } },
];
const body = vectors
.map((vector) => JSON.stringify(vector))
.join("\n")
.trim();
const client = new Cloudflare({
apiToken: env.CLOUDFLARE_VECTORIZE_API_TOKEN,
});
const insertUsingSdk = await client.vectorize.indexes.upsert(
index.name,
{
account_id: env.CLOUDFLARE_ACC_ID,
body: body,
},
{
headers: {
"Content-Type": "application/x-ndjson",
},
},
);
const insertUsingFetch = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${env.CLOUDFLARE_ACC_ID}/vectorize/v2/indexes/${index.name}/insert`,
{
method: "POST",
body: body,
headers: {
Authorization: `Bearer ${env.CLOUDFLARE_VECTORIZE_API_TOKEN}`,
"Content-Type": "application/x-ndjson",
},
},
);
OS
macOS
Runtime version
Typescript 5.6.3
Library version
v4.3.0
Metadata
Metadata
Assignees
Labels
No labels