POST
/
completions

Body

projectId
string
required

The Commonbase project ID.

userId
string

An optional custom string used to identify users in the invocation logs.

prompt
string

The text used to generate a completion when providerConfig.params.type: 'text' is set.

One of prompt or messages must be sent with each request.

messages
ChatMessage[]

A list of messages for chat completions. providerConfig.params.type must be set to 'chat', otherwise these messages are ignored.

One of prompt or messages must be sent with each request.

functions
ChatFunction[]

A list of functions that the LLM can call.

functionCall
'none' | 'auto' | { name: string }

A parameter used to tell the LLM to call a specific function.

providerConfig
ProviderConfig

The completion provider configuration. A different configuration object is used for each provider.

stream
boolean
default: "false"

Determines whether to stream a response as it is generated.

showUsage
boolean
default: "false"

Determines whether to return token count and cost of the LLM response.

Success Response

completed
boolean

Indicates whether the completion is finished. completed may be false while streaming a partial response.

invocationId
string

The ID of the invocation.

projectId
string

The ID of the project.

type
'chat' | 'text'

The type of the completion response.

model
string

The name of the LLM model used for the completion.

choices
object[]

The result of the completion. The structure of this object may vary depending on the provider and type of completion that is requested.

See provider documentation for more details:

usage
object

The usage information about the token costs of the invocation.

usage_cost
float

The cost of the invocation in dollars.

Error Response

error
string

An error message explaining why the response failed.

invocationId
string

The ID of the invocation.