@archastro/sdk
    Preparing search index...

    Class CompletionResource

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Create a chat completion Sends a list of messages to the configured AI provider and returns a single completion. Use this endpoint when you want direct, low-level access to the underlying model without any workflow or agent orchestration. The authenticated app must have the llm_calls entitlement enabled on its plan. Requests that exceed the plan quota are rejected with 402. Token usage is recorded against the authenticated app and organization. Supply tools and tool_choice to enable OpenAI-compatible function calling. Use server_tools to activate platform-managed tools such as search that run on the server side before the response is returned.

      Parameters

      • input: {
            context?: Record<string, unknown>;
            messages: {
                content?: string;
                content_parts?: Record<string, unknown>[];
                resume_token?: string;
                role: string;
                structured_output?: unknown;
                tool_calls?: {
                    arguments: Record<string, unknown>;
                    id: string;
                    name: string;
                    thought_signature?: string;
                }[];
                tool_results?: {
                    content?: string;
                    id: string;
                    name: string;
                    resolution?: unknown;
                }[];
            }[];
            opts: {
                max_tokens?: number;
                model: string;
                server_tools?: Record<string, unknown>[];
                temperature?: number;
                tool_choice?: string;
                tools?: {
                    function: {
                        description?: string;
                        name: string;
                        parameters: Record<string, unknown>;
                    };
                    type: string;
                }[];
            };
        }

        Request body.

        • Optionalcontext?: Record<string, unknown>

          Key-value map used to resolve template variables in message content. Omit if messages contain no templates.

        • messages: {
              content?: string;
              content_parts?: Record<string, unknown>[];
              resume_token?: string;
              role: string;
              structured_output?: unknown;
              tool_calls?: {
                  arguments: Record<string, unknown>;
                  id: string;
                  name: string;
                  thought_signature?: string;
              }[];
              tool_results?: {
                  content?: string;
                  id: string;
                  name: string;
                  resolution?: unknown;
              }[];
          }[]

          Ordered list of conversation messages to send to the model.

        • opts: {
              max_tokens?: number;
              model: string;
              server_tools?: Record<string, unknown>[];
              temperature?: number;
              tool_choice?: string;
              tools?: {
                  function: {
                      description?: string;
                      name: string;
                      parameters: Record<string, unknown>;
                  };
                  type: string;
              }[];
          }

          Model and sampling configuration for this request.

      Returns Promise<AICompletionResult>

      The completed AI response, including the generated message, finish reason, and token usage.

    • Stream a chat completion Streams a chat completion over Server-Sent Events. Emits message_delta, message_complete, tool_call_*, tool_result, and a terminal done (or error) event. Same request shape as the non-streaming completion endpoint; the app must have the llm_calls entitlement.

      Parameters

      • input: {
            context?: Record<string, unknown>;
            messages: {
                content?: string;
                content_parts?: Record<string, unknown>[];
                resume_token?: string;
                role: string;
                structured_output?: unknown;
                tool_calls?: {
                    arguments: Record<string, unknown>;
                    id: string;
                    name: string;
                    thought_signature?: string;
                }[];
                tool_results?: {
                    content?: string;
                    id: string;
                    name: string;
                    resolution?: unknown;
                }[];
            }[];
            opts: {
                max_tokens?: number;
                model: string;
                server_tools?: Record<string, unknown>[];
                temperature?: number;
                tool_choice?: string;
                tools?: {
                    function: {
                        description?: string;
                        name: string;
                        parameters: Record<string, unknown>;
                    };
                    type: string;
                }[];
            };
        }

        Request body.

        • Optionalcontext?: Record<string, unknown>

          Key-value map used to resolve template variables in message content. Omit if messages contain no templates.

        • messages: {
              content?: string;
              content_parts?: Record<string, unknown>[];
              resume_token?: string;
              role: string;
              structured_output?: unknown;
              tool_calls?: {
                  arguments: Record<string, unknown>;
                  id: string;
                  name: string;
                  thought_signature?: string;
              }[];
              tool_results?: {
                  content?: string;
                  id: string;
                  name: string;
                  resolution?: unknown;
              }[];
          }[]

          Ordered list of conversation messages to send to the model.

        • opts: {
              max_tokens?: number;
              model: string;
              server_tools?: Record<string, unknown>[];
              temperature?: number;
              tool_choice?: string;
              tools?: {
                  function: {
                      description?: string;
                      name: string;
                      parameters: Record<string, unknown>;
                  };
                  type: string;
              }[];
          }

          Model and sampling configuration for this request.

      Returns AsyncIterable<
          | { data: AIChatStreamDone; event: "done" }
          | { data: AIChatStreamError; event: "error" }
          | { data: AIChatStreamMessageComplete; event: "message_complete" }
          | { data: AIChatStreamMessageDelta; event: "message_delta" }
          | { data: AIChatStreamToolCallDelta; event: "tool_call_delta" }
          | { data: AIChatStreamToolResult; event: "tool_result" },
      >

      Server-Sent Events stream