Conversations
A conversation stores the items of a multi-turn exchange on the server. Pass its ID as
conversation to responses.create(). The conversation's items are
prepended to your input, and the new input and output are appended to it. You don't need to replay
history or chain response IDs.
The endpoints are OpenAI-compatible, under https://api.glexir.com/v1/conversations.
Quick start
Operations
| SDK method | HTTP | Returns |
|---|---|---|
conversations.create(body?, options?) | POST /v1/conversations | Conversation |
conversations.retrieve(id, options?) | GET /v1/conversations/{id} | Conversation |
conversations.update(id, body, options?) | POST /v1/conversations/{id} | Conversation |
conversations.delete(id, options?) | DELETE /v1/conversations/{id} | ConversationDeleted |
conversations.items.create(id, params, options?) | POST /v1/conversations/{id}/items | ConversationItemList |
conversations.items.list(id, query?, options?) | GET /v1/conversations/{id}/items | PagePromise<ConversationItem> |
conversations.items.retrieve(id, itemId, query?, options?) | GET /v1/conversations/{id}/items/{itemId} | ConversationItem |
conversations.items.delete(id, itemId, options?) | DELETE /v1/conversations/{id}/items/{itemId} | Conversation |
Every method takes request options as its last argument. Conversations are not billed by themselves; you pay for the responses that use them.
A conversation belongs to the Glexir organization that created it. Using another conversation ID
with any of these endpoints, or with responses.create(), returns 404
(No conversation found with id '...').
The Conversation object
idstringoptional- The conversation ID, for example
conv_.... object"conversation"optional- Always conversation.
created_atnumberoptional- Unix timestamp in seconds.
metadataRecord<string, string> | nulloptional- Your key/value pairs.
_request_idstring | nulloptional- Added by the SDK: the
x-request-idheader.
Create a conversation
conversations.create(body?, options?). Both fields are optional.
itemsResponseInputItem[] | nulloptional- Initial items, at most 20. Same item types as Responses
input. metadataRecord<string, string> | nulloptional- Up to 16 key/value pairs. Keys up to 64 characters, values up to 512.
The gateway forwards only items and metadata; other fields are dropped. Items go through the
same checks as Responses input: audio parts and items from OpenAI-hosted tools return 400
unsupported_on_glexir, and file_id references must be files you uploaded through Glexir. See
Input the gateway rejects.
Retrieve a conversation
Update a conversation
conversations.update(conversationId, body, options?) replaces the metadata. Metadata is the only
field you can change.
ConversationUpdateParams is { metadata: Record<string, string> | null }. metadata is required;
without it the gateway returns 400 ("metadata is required.").
Delete a conversation
Returns ConversationDeleted: { id, deleted, object: "conversation.deleted" }. Deleting a
conversation does not delete its items. After deletion the ID returns 404 on Glexir.
Add items
conversations.items.create(conversationId, params, options?) appends up to 20 items.
itemsResponseInputItem[]required- The items to add, at most 20.
includeResponseIncludable[]optional- Extra fields to include in the returned items. Sent as a query parameter.
Returns ConversationItemList: { object: "list", data, first_id, last_id, has_more }. The same input
checks as create() apply.
List items
conversations.items.list(conversationId, query?, options?) returns a PagePromise<ConversationItem>.
Iterate it with for await to walk every page, or await it for one page. Items are newest first
unless you pass order: "asc". See Pagination.
afterstringoptional- Cursor: list items after this one. The SDK fills it in from last_id while paging.
limitnumberoptional- Items per page.
order"asc" | "desc"optionaldefault"desc"- Sort order.
includeResponseIncludable[]optional- Extra fields to include.
ConversationItem is the same type as ResponseItem: messages, reasoning items, function and custom
tool calls with their outputs, and compaction items. Conversation messages may also use a plain
text content part.
Retrieve an item
conversations.items.retrieve(conversationId, itemId, query?, options?). ItemRetrieveParams is
{ include?: ResponseIncludable[] }.
Delete an item
conversations.items.delete(conversationId, itemId, options?) removes the item and returns the
updated Conversation.
Using a conversation with Responses
- Pass
conversation: "conv_123"orconversation: { id: "conv_123" }toresponses.create(). - Do not combine
conversationwithprevious_response_id. - Before running a request with a
conversation, Glexir reserves credit for about 50,000 tokens of earlier context, because it does not track the conversation's size. The reservation is released and you pay only for actual usage. If your balance is low, this reservation can cause a 402. - Every file and response referenced in the request must live on the same upstream account as the
conversation. Otherwise the request fails with 409
cross_account_reference.
Errors
| Status | code | Cause |
|---|---|---|
| 400 | unsupported_on_glexir | An item contains audio input or comes from an OpenAI-hosted tool. |
| 400 | null | Missing metadata on update, or an items value that is not an array of objects. |
| 404 | null | The conversation or a referenced file is not yours. |
| 409 | cross_account_reference | Referenced objects live on different upstream accounts. |
See HTTP error codes for errors every endpoint can return.