API Documentation
/v1/completion/typed

/v1/completion/typed

This endpoint generates Language Model completions that are typed according to the specified schema and type name. This allows a greater level of customization and control over the completions generated.

Request: POST /v1/completion/typed

Headers

  • Content-Type: application/json
  • Authorization: Bearer <your_api_key>

Body

The request accepts a JSON body with the following properties:

FieldTypeDescriptionRequired
promptstringThe prompt to generate from.Yes
schemastringA set of exported TypeScript definitions.Yes
type_namestringThe type name for the typed completion. Must be part of the schema.Yes
max_tokensuintThe maximum number of tokens to generate.No
temperaturefloat64The value used to modulate the next token probabilities.No
top_pfloat64If set to float < 1, only the most probable tokens with probabilities that add up to top_p or higher are kept for generation.No
stop[]stringA list of strings that, when generated, will stop the completion.No
presence_penaltyfloat64The parameter for presence penalty.No
frequency_penaltyfloat64The parameter for frequency penalty.No

Important

Type definitions in the schema must be exported. For example:

export type BasicSentence {
  text: string;
}

type_name must be a valid type name in the schema. For example:

export type BasicSentence {
  text: string;
}

In this case, BasicSentence is a valid type_name.

Example

{
  "prompt": "Write a sentence",
  "max_tokens": 20,
  "temperature": 0.8,
  "top_p": 0.9,
  "stop": ["."],
  "presence_penalty": 0.6,
  "frequency_penalty": 0.5,
  "schema": "export type BasicSentence {
  text: string;
}",
  "type_name": "BasicSentence"
}

Response

When a request to the /v1/completion/typed endpoint is successful, the response will contain the following fields:

FieldTypeDescription
idUUIDA unique identifier for the completion request.
objectstringThe type of object returned
createdtime (ISO 8601 format)The timestamp of when the completion was generated.
choicesarray of CompletionChoiceAn array of completion choices. Each choice contains generated text and other related information.
usageUsage objectProvides information about the number of tokens used in the prompt, completion, and the prediction time in milliseconds.

CompletionChoice

Each CompletionChoice in the choices array has the following fields:

FieldTypeDescription
textstringThe generated completion text.
createdintThe timestamp of when the choice was created.
modelstringThe name of the model that was used to generate this choice.
finish_reasonstringThe reason the generation for this choice was finished (e.g., "stop token reached").
usageUsage objectProvides information about the number of tokens used for this specific choice.

Usage

The Usage object contains information about token usage and prediction time:

FieldTypeDescription
prompt_tokensintThe number of tokens in the provided prompt.
prediction_time_msint64The time taken, in milliseconds, to generate the completion.
completion_tokensintThe number of tokens in the generated completion.
total_tokensintThe total number of tokens, including both prompt and completion.