---
title: "Create a conversation (OpenAI Conversations)"
description: "Creates a conversation, optionally with its first items and metadata. Name its ID in `conversation` on Create a response to continue it on any model. A conversation is kept for 30 days after it was last read or written and holds at most 4 MiB of items. Conversations are kept by the gateway, not a provider, so they call no model and aren't rate limited, billed or logged. A conversation belongs to the project that made it; another project gets `404`."
---

**POST** `https://gateway.respan.ai/v1/conversations`

Creates a conversation, optionally with its first items and metadata. Name its ID in `conversation` on Create a response to continue it on any model. A conversation is kept for 30 days after it was last read or written and holds at most 4 MiB of items. Conversations are kept by the gateway, not a provider, so they call no model and aren't rate limited, billed or logged. A conversation belongs to the project that made it; another project gets `404`.

## Servers

`https://gateway.respan.ai`: Respan gateway

## Authentication

### RespanApiKey

Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer &lt;RESPAN_API_KEY&gt;. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -&gt; Providers or respan_params.credential_override in the request body, not in this authentication field.

HTTP scheme: `bearer`; format: `Respan API key`.


```http
Authorization: Bearer $RESPAN_API_KEY
```


## Request body

The request body is optional.

### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Optional body | - |
| `items` | `array<object>` | Optional | Maximum items: `20` |
| `items[]` | `object` | Array item | A Responses input item, such as `{"role": "user", "content": "Hi"}`.<br />Additional properties are allowed |
| `metadata` | `object` | Optional | Up to 16 key-value pairs; keys up to 64 characters, values up to 512.<br />Maximum properties: `16` |
| `metadata.<key>` | `string` | Map value | Maximum length: `512` |


<details class="api-schema-source">
<summary>OpenAPI request schema</summary>


```json
{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "maxItems": 20,
      "items": {
        "type": "object",
        "additionalProperties": true,
        "description": "A Responses input item, such as `{\"role\": \"user\", \"content\": \"Hi\"}`."
      }
    },
    "metadata": {
      "type": "object",
      "additionalProperties": {
        "type": "string",
        "maxLength": 512
      },
      "maxProperties": 16,
      "description": "Up to 16 key-value pairs; keys up to 64 characters, values up to 512."
    }
  }
}
```

</details>

##### Example


```json
{
  "items": [
    {
      "role": "user",
      "content": "I was charged twice."
    }
  ],
  "metadata": {
    "topic": "billing"
  }
}
```


## Examples

### Create a conversation

#### Headers


```json
{
  "Authorization": "Bearer YOUR_RESPAN_API_KEY"
}
```


#### Request


```json
{
  "items": [
    {
      "role": "user",
      "content": "I was charged twice."
    }
  ],
  "metadata": {
    "topic": "billing"
  }
}
```


#### Response


```json
{
  "body": {
    "id": "conv_6f0d3c1e9b2a4f5e8d7c6b5a49382716",
    "object": "conversation",
    "created_at": 1795398300,
    "metadata": {
      "topic": "billing"
    }
  }
}
```


#### cURL


```bash
curl --request POST 'https://gateway.respan.ai/v1/conversations' \
  --header "Authorization: Bearer $RESPAN_API_KEY" \
  --header 'Content-Type: application/json' \
  --data @- <<'JSON'
{
  "items": [
    {
      "role": "user",
      "content": "I was charged twice."
    }
  ],
  "metadata": {
    "topic": "billing"
  }
}
JSON
```


<details>
<summary>Python</summary>



```python
import json
import os
import urllib.request

payload = json.loads(r'''{
  "items": [
    {
      "role": "user",
      "content": "I was charged twice."
    }
  ],
  "metadata": {
    "topic": "billing"
  }
}''')

request = urllib.request.Request(
    "https://gateway.respan.ai/v1/conversations",
    data=json.dumps(payload).encode(),
    headers={
        "Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
        "Content-Type": "application/json",
    },
    method="POST",
)
with urllib.request.urlopen(request) as response:
    print(response.read().decode())
```


</details>

<details>
<summary>TypeScript</summary>



```typescript
const response = await fetch("https://gateway.respan.ai/v1/conversations", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.RESPAN_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "items": [
      {
        "role": "user",
        "content": "I was charged twice."
      }
    ],
    "metadata": {
      "topic": "billing"
    }
  }),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.text());
```


</details>

## Responses

### 200

The new conversation.

#### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Body | Reference: `#/components/schemas/GatewayConversation` |
| `id` | `string` | Required in parent | Example: `"conv_6f0d3c1e9b2a4f5e8d7c6b5a49382716"` |
| `object` | `string` | Required in parent | Allowed: `"conversation"` |
| `created_at` | `integer` | Required in parent | Unix seconds. |
| `metadata` | `object` | Required in parent | - |
| `metadata.<key>` | `string` | Map value | - |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "$ref": "#/components/schemas/GatewayConversation"
}
```

</details>

##### Example


```json
{
  "id": "conv_6f0d3c1e9b2a4f5e8d7c6b5a49382716",
  "object": "conversation",
  "created_at": 1795398300,
  "metadata": {
    "topic": "billing"
  }
}
```


### 400

Invalid items or metadata.

#### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Body | OpenAI-style error written by the gateway.<br />Reference: `#/components/schemas/GatewayError` |
| `error` | `object` | Required in parent | - |
| `error.message` | `string` | Required in parent | - |
| `error.type` | `string` | Optional | - |
| `error.param` | `string or null` | Optional | - |
| `error.code` | `string or null` | Optional | - |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "$ref": "#/components/schemas/GatewayError"
}
```

</details>

### 403

The API key is missing, invalid or expired.

#### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Body | OpenAI-style error written by the gateway.<br />Reference: `#/components/schemas/GatewayError` |
| `error` | `object` | Required in parent | - |
| `error.message` | `string` | Required in parent | - |
| `error.type` | `string` | Optional | - |
| `error.param` | `string or null` | Optional | - |
| `error.code` | `string or null` | Optional | - |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "$ref": "#/components/schemas/GatewayError"
}
```

</details>

##### Example


```json
{
  "error": {
    "message": "Your API key is invalid or expired, please check your API key in the platform settings.",
    "type": "error",
    "param": null,
    "code": "error"
  }
}
```


## OpenAPI source

The operation and referenced components below retain the complete OpenAPI definitions, including constraints and examples.

<!-- openapi-operation:start -->
<details class="api-schema-source">
<summary>OpenAPI operation</summary>


```json
{
  "summary": "Create a conversation (OpenAI Conversations)",
  "operationId": "createConversation",
  "tags": [
    "Gateway"
  ],
  "description": "Creates a conversation, optionally with its first items and metadata. Name its ID in `conversation` on Create a response to continue it on any model. A conversation is kept for 30 days after it was last read or written and holds at most 4 MiB of items. Conversations are kept by the gateway, not a provider, so they call no model and aren't rate limited, billed or logged. A conversation belongs to the project that made it; another project gets `404`.",
  "servers": [
    {
      "url": "https://gateway.respan.ai",
      "description": "Respan gateway"
    }
  ],
  "security": [
    {
      "RespanApiKey": []
    }
  ],
  "parameters": [],
  "requestBody": {
    "required": false,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "items": {
              "type": "array",
              "maxItems": 20,
              "items": {
                "type": "object",
                "additionalProperties": true,
                "description": "A Responses input item, such as `{\"role\": \"user\", \"content\": \"Hi\"}`."
              }
            },
            "metadata": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "maxLength": 512
              },
              "maxProperties": 16,
              "description": "Up to 16 key-value pairs; keys up to 64 characters, values up to 512."
            }
          }
        },
        "example": {
          "items": [
            {
              "role": "user",
              "content": "I was charged twice."
            }
          ],
          "metadata": {
            "topic": "billing"
          }
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "The new conversation.",
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/GatewayConversation"
          },
          "example": {
            "id": "conv_6f0d3c1e9b2a4f5e8d7c6b5a49382716",
            "object": "conversation",
            "created_at": 1795398300,
            "metadata": {
              "topic": "billing"
            }
          }
        }
      }
    },
    "400": {
      "description": "Invalid items or metadata.",
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/GatewayError"
          }
        }
      }
    },
    "403": {
      "description": "The API key is missing, invalid or expired.",
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/GatewayError"
          },
          "example": {
            "error": {
              "message": "Your API key is invalid or expired, please check your API key in the platform settings.",
              "type": "error",
              "param": null,
              "code": "error"
            }
          }
        }
      }
    }
  },
  "x-fern-examples": [
    {
      "name": "Create a conversation",
      "headers": {
        "Authorization": "Bearer YOUR_RESPAN_API_KEY"
      },
      "request": {
        "items": [
          {
            "role": "user",
            "content": "I was charged twice."
          }
        ],
        "metadata": {
          "topic": "billing"
        }
      },
      "response": {
        "body": {
          "id": "conv_6f0d3c1e9b2a4f5e8d7c6b5a49382716",
          "object": "conversation",
          "created_at": 1795398300,
          "metadata": {
            "topic": "billing"
          }
        }
      }
    }
  ]
}
```

</details>
<!-- openapi-operation:end -->

<!-- openapi-path-item:start -->
<details class="api-schema-source">
<summary>OpenAPI path metadata</summary>


```json
{}
```

</details>
<!-- openapi-path-item:end -->

<!-- openapi-components:start -->
<details class="api-schema-source">
<summary>Referenced OpenAPI components</summary>


```json
{
  "schemas": {
    "GatewayConversation": {
      "type": "object",
      "required": [
        "id",
        "object",
        "created_at",
        "metadata"
      ],
      "properties": {
        "id": {
          "type": "string",
          "example": "conv_6f0d3c1e9b2a4f5e8d7c6b5a49382716"
        },
        "object": {
          "type": "string",
          "enum": [
            "conversation"
          ]
        },
        "created_at": {
          "type": "integer",
          "description": "Unix seconds."
        },
        "metadata": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        }
      }
    },
    "GatewayError": {
      "type": "object",
      "required": [
        "error"
      ],
      "description": "OpenAI-style error written by the gateway.",
      "properties": {
        "error": {
          "type": "object",
          "required": [
            "message"
          ],
          "properties": {
            "message": {
              "type": "string"
            },
            "type": {
              "type": "string"
            },
            "param": {
              "type": "string",
              "nullable": true
            },
            "code": {
              "type": "string",
              "nullable": true
            }
          }
        }
      }
    }
  },
  "securitySchemes": {
    "RespanApiKey": {
      "type": "http",
      "scheme": "bearer",
      "bearerFormat": "Respan API key",
      "description": "Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer <RESPAN_API_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan_params.credential_override in the request body, not in this authentication field.",
      "x-fern-bearer": {
        "name": "respanApiKey",
        "env": "RESPAN_API_KEY"
      }
    }
  }
}
```

</details>
<!-- openapi-components:end -->
