# Create Batch — OpenAI (ChatGPT)

> Creates and executes a batch from an uploaded file of requests. See the documentation

- Key: `openai-create-batch`
- Type: Action (Write)
- Version: 0.1.5
- App: OpenAI (ChatGPT) (`openai`) — https://pipedream.com/apps/openai.md
- This page (HTML): https://pipedream.com/apps/openai/actions/create-batch
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/openai/actions/create-batch/create-batch.mjs

## Description

Creates and executes a batch from an uploaded file of requests. [See the documentation](https://platform.openai.com/docs/api-reference/batch/create)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `endpoint` | `string` | Yes | The endpoint to be used for all requests in the batch |
| `fileId` | `string` | No | The ID of the file to use for this request. Options are loaded from the connected account. |
| `filePath` | `string` | No | The .jsonl file to process. Provide either a file URL or a path to a file in the /tmp directory (for example, /tmp/myFile.jpg) |
| `metadata` | `object` | No | Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. |
| `syncDir` | `dir` | No | SyncDir |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "openai",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "openai-create-batch",
  arguments: {
    endpoint: "Endpoint",
    fileId: "File ID",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "openai-create-batch",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    openai: { authProvisionId: "apn_xxxxxxx" },
    endpoint: "Endpoint",
    fileId: "File ID",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "openai-create-batch",
    "configured_props": {
      "openai": { "authProvisionId": "apn_xxxxxxx" },
      "endpoint": "Endpoint",
      "fileId": "File ID"
    }
  }'
```

---

- App: https://pipedream.com/apps/openai.md · All apps: https://pipedream.com/apps
