ACTIONS
  • Home
  • My Actions
  • My Projects
  • My Packages
xAI -> Create a Chat Completion
Function Documentation: xAI -> Create a Chat Completion

Action summary

xAI -> Create a Chat Completion

Xano

Function Documentation: xAI -> Create a Chat Completion

xAI API documentation

Overview

This function generates a completion using the xAI API based on a user-provided request. It requires parameters such as the model & prompt text. The function validates environment variables and conditions before making an API request and processing the response.

Inputs

  1. xai_api_key (registry|text) Required Sensitive data
    • Description: The API key for your xAI account.
  2. model (enum) Required
    • Description: Specifies the model to be used for generating the completion.
    • Options:
      • Available models will be specified by xAI
  3. message (text) Required
    • Description: The input prompt that will be sent to the xAI API for generating the completion.
  4. system (text) Required
    • Description: Initial instructions that shape the AI's behavior, role, and response style. Sets the context and guidelines for how the AI should interact throughout the conversation on task.

Function Stack

1. xAI API Request

  1. API Request to https://api.x.ai/v1/completions
    • Purpose: Sends a request to the xAI API using the specified model and prompt.
  2. Precondition: xai_api_response.status == 200
    • Purpose: Confirms that the API request was successful (HTTP status code 200).

2. xAI API Response

  1. Create Variable: response
    • Purpose: Stores the response from the xAI API.

Response

  • The function returns the generated completion in a structured format

Success Response

Response provided as a string.

Error Response

{
  "error": {
    "message": "Invalid API key provided",
    "type": "invalid_request_error"
  }
}

Example

Input

{
  "model": "grok-beta",
  "prompt": "What is Obama's height?"
}

Response

"Barack Obama is 6 feet 1 inch tall (185 cm)."  

Version notes

2024-11-05 16:05:11
Current
2024-11-05T06:05:13.000+00:00