POST
/
completions
Authorization
Body
curl --location --request POST 'https://api.commonbase.com/completions' \
--header 'Authorization: API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "projectId": "PROJECT_ID",
  "prompt": "Hello!",
  "providerConfig": {
    "provider": "cb-openai-eu",
    "params": {
      "type": "text",
      "model": "<model_name>"
    }
  },
  "stream": true,
  "showUsage": true
}'
{
  "completed": true,
  "invocationId": "<invocation_id>",
  "projectId": "<project_id>",
  "type": "text",
  "model": "<model_name>",
  "choices": [
    {
      "text": "<completion_response>",
      "index": 0,
      "finish_reason": "stop",
      "logprobs": null
    }
  ],
  "usage": {
    "total_tokens": "124",
    "prompt_tokens": "37",
    "total_tokens": "87"
  },
  "usage_cost": 0.0004
}

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.