Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Create items

client.Conversations.Items.New(ctx, conversationID, params) (*ConversationItemList, error)
POST/conversations/{conversation_id}/items

Create items in a conversation with the given ID.

ParametersExpand Collapse
conversationID string
params ItemNewParams
ReturnsExpand Collapse
type ConversationItemList struct{…}

A list of Conversation items.

A list of conversation items.

FirstID string

The ID of the first item in the list.

HasMore bool

Whether there are more items available.

LastID string

The ID of the last item in the list.

Object List

The type of object returned, must be list.

Create items

package main

import (
  "context"
  "fmt"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/conversations"
  "github.com/openai/openai-go/option"
  "github.com/openai/openai-go/responses"
)

func main() {
  client := openai.NewClient(
    option.WithAPIKey("My API Key"),
  )
  conversationItemList, err := client.Conversations.Items.New(
    context.TODO(),
    "conv_123",
    conversations.ItemNewParams{
      Items: []responses.ResponseInputItemUnionParam{responses.ResponseInputItemUnionParam{
        OfMessage: &responses.EasyInputMessageParam{
          Content: responses.EasyInputMessageContentUnionParam{
            OfString: openai.String("string"),
          },
          Role: responses.EasyInputMessageRoleUser,
          Type: responses.EasyInputMessageTypeMessage,
        },
      }},
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", conversationItemList.FirstID)
}
{
  "object": "list",
  "data": [
    {
      "type": "message",
      "id": "msg_abc",
      "status": "completed",
      "role": "user",
      "content": [
        {"type": "input_text", "text": "Hello!"}
      ]
    },
    {
      "type": "message",
      "id": "msg_def",
      "status": "completed",
      "role": "user",
      "content": [
        {"type": "input_text", "text": "How are you?"}
      ]
    }
  ],
  "first_id": "msg_abc",
  "last_id": "msg_def",
  "has_more": false
}
Returns Examples
{
  "object": "list",
  "data": [
    {
      "type": "message",
      "id": "msg_abc",
      "status": "completed",
      "role": "user",
      "content": [
        {"type": "input_text", "text": "Hello!"}
      ]
    },
    {
      "type": "message",
      "id": "msg_def",
      "status": "completed",
      "role": "user",
      "content": [
        {"type": "input_text", "text": "How are you?"}
      ]
    }
  ],
  "first_id": "msg_abc",
  "last_id": "msg_def",
  "has_more": false
}