Skip to main content

Grok by xAI

Grok is xAI's advanced language model API that provides powerful AI capabilities for chat completions, function calling, and text generation. The Grok API connector enables you to interact with Grok models through the xAI API, allowing you to generate text responses, perform function calling with external tools, and leverage AI-powered capabilities in your data workflows. This connector is particularly useful for applications that need to generate content, perform language analysis, integrate AI capabilities into data processing pipelines, or build conversational AI applications.

Grok by xAI icon

Power end-to-end data operations for your Grok by xAI API with Nexla. Our bi-directional Grok by xAI connector is purpose-built for Grok by xAI, making it simple to ingest data, sync it across systems, and deliver it anywhere — all with no coding required. Nexla turns API-sourced data into ready-to-use, reusable data products and makes it easy to send data to Grok by xAI or any other destination. With comprehensive monitoring, lineage tracking, and access controls, Nexla keeps your Grok by xAI workflows fast, secure, and fully governed.

Features

Type: API

SourceDestination

  • Seamless API Integration: Connect to any endpoint as source or destination without coding, with automatic data product creation
  • Visual Composition & Chaining: Build complex integrations using visual templates, chain API calls, and compose workflows with data validation and filtering
  • API Proxy: Expose curated slices of your data securely with a secure and customizable API proxy that validates and transforms data on the fly
  • Request optimization with intelligent batching, retry, and caching to minimize API calls and costs

Prerequisites

Before creating a Grok by xAI credential, you'll need to obtain an API key from your xAI account. xAI provides API keys for programmatic access to the Grok API, which are used to authenticate API requests.

To obtain a Grok API key:

  1. Log in to your xAI account or create an account at https://x.ai if you don't have one.

  2. Navigate to the API settings or developer section of your xAI account dashboard. This is typically accessible from your account settings or a dedicated API/Developer section.

  3. In the API settings, locate the option to create or generate a new API key. xAI API keys typically start with the prefix xai-.

  4. Click Create API Key or Generate New Key to create a new API key for your application.

  5. Copy the API key immediately after generation, as it may only be displayed once for security purposes. Store it securely, as you'll need both the API key and the ability to regenerate it if needed.

  6. Note the base URL for the Grok API (typically https://api.x.ai) and the API version you'll be using (typically v1 for the current Grok API version).

For detailed information about Grok API authentication and API key management, refer to the xAI API Documentation.

Authenticate

Credentials required

Authenticate using your Grok API Key

FieldRequiredSecretDescription
API KeyYesYesxAI-provided Grok API key (starts with xai-)
Base URLYesNoParameter for defining the base URL for the Grok API
API VersionYesNoParameter for defining the API version for Grok API requests

Create a credential in Nexla

  1. To create a new Grok by xAI credential, after selecting the data source/destination type, click the Add Credential tile to open the Add New Credential overlay.

New Credential Overlay – Grok by xAI

GrokCred.png
  1. Enter a name for the credential in the Credential Name field and a short, meaningful description in the Credential Description field.

  2. In the API Key field, enter the Grok API key that you obtained from your xAI account. This is the API key that starts with xai- and is used to authenticate requests to the Grok API.

    The API key is sensitive information and should be kept secure. If you've lost your API key, you'll need to generate a new one in your xAI account settings. API keys are used in the Authorization header as a Bearer token for all API requests.

  3. In the Base URL field, enter the base URL for the Grok API. The default value is https://api.x.ai, which is the standard base URL for xAI's Grok API. You typically won't need to change this unless you're using a custom endpoint.

  4. In the API Version field, enter the API version you want to use. The default value is v1, which is the current version of the Grok API. You can specify a different version if your organization uses a specific API version.

  5. Click the Save button at the bottom of the overlay to save the configured credential. The newly added credential will now appear in a tile on the Authenticate screen during data source/destination creation and can be selected for use with a new data source or destination.

Use as a data source

To create a new data flow, navigate to the Integrate section, and click the New Data Flow button. Select the Grok by xAI connector tile, then select the credential that will be used to connect to the xAI instance, and click Next; or, create a new Grok by xAI credential for use in this flow.

Endpoint templates

Nexla provides pre-built templates that can be used to rapidly configure data sources to ingest data from common Grok API endpoints. Select the endpoint from which this source will fetch data from the Endpoint pulldown menu. Available endpoint templates are listed in the expandable boxes below.

Chat Completions

This endpoint generates text responses from Grok based on system and user prompts. Use this endpoint when you need to generate conversational responses, perform text analysis, or leverage Grok's language understanding capabilities for your applications.

  • Enter the Grok model name in the Model field. Available models include grok-1, grok-3, and other Grok model variants. The default value is grok-3, which is the latest Grok model. You can specify other available models based on your requirements.
  • Optionally, enter a system message in the System Message field to guide the model's behavior and set the context for the conversation. The system message helps define the assistant's role, tone, and instructions. The default value is You are a helpful assistant. You can customize this to match your specific use case.
  • Enter the user prompt or message in the User Prompt field. This is the main input from the user that the model will process and respond to. This field is required and should contain the question, request, or text you want Grok to analyze or respond to.
  • Optionally, enter a temperature value in the Temperature field to control the randomness and creativity of the model's output. Temperature controls the probability distribution of token selection. Lower values (e.g., 0.1-0.3) produce more focused, deterministic, and factual responses, while higher values (e.g., 0.7-1.0) produce more creative and varied responses. The default value is 0.7, which provides a balance between creativity and consistency.
  • Optionally, enter a Top-P value in the Top P field to control diversity via nucleus sampling. Top-P limits token selection to those whose cumulative probability mass reaches the specified threshold. Higher values (closer to 1) increase diversity by considering more token options, while lower values make the model more conservative. The default value is 1, which allows maximum diversity.
  • Optionally, enter the maximum number of tokens in the Max Tokens field to limit the length of the generated response. This helps control API costs and response length. The default value is 256 tokens. For longer responses, you can increase this value, but be aware that longer responses consume more API quota.

The Chat Completions endpoint uses POST requests to send prompts to the Grok model. Adjust temperature and Top-P values based on your use case: use lower values for factual content and data extraction, and use higher values for creative writing and brainstorming. The combination of these parameters allows you to fine-tune the model's output to match your specific requirements. For more information about the Chat Completions endpoint, refer to the xAI API Documentation.

Function Calling

This endpoint enables Grok to call external functions using function schema definitions. Use this endpoint when you need to integrate Grok with external tools, APIs, or services by allowing the model to invoke functions based on user requests.

  • Enter the function schema in JSON format in the Function Schema field. This schema defines the functions available to the model, including function names, descriptions, and parameters. The schema should follow the JSON schema format for function definitions. This field is required and must contain valid JSON schema definitions for the functions you want Grok to be able to call.
  • Enter the Grok model name in the Model field. Available models include grok-1, grok-3, and other Grok model variants. The default value is grok-3. Ensure the model you select supports function calling capabilities.
  • Optionally, enter a system message in the System Message field to guide the model's behavior and provide context about the available functions. The system message helps define how the model should use the functions. The default value is You are a helpful assistant. You can customize this to provide specific instructions about function usage.
  • Enter the user prompt or message in the User Prompt field. This is the main input from the user that may trigger function calls. This field is required and should contain the question or request that might require the model to call one or more of the defined functions.
  • Optionally, enter a temperature value in the Temperature field to control the randomness of the model's output. The default value is 0.7. Lower values produce more deterministic responses, while higher values allow more creative interpretations of when to call functions.
  • Optionally, enter a Top-P value in the Top P field to control diversity. The default value is 1. Adjust this based on your needs for function calling consistency.
  • Optionally, enter the maximum number of tokens in the Max Tokens field to limit the response length. The default value is 256 tokens. Function calling responses may require more tokens if multiple function calls are made.

Function calling allows Grok to interact with external systems by invoking functions based on user requests. The function schema must be properly formatted JSON that defines the available functions, their parameters, and descriptions. The model will analyze the user's request and determine which functions to call, if any. For more information about function calling and the Function Calling endpoint, refer to the xAI API Documentation.

List Models

This endpoint retrieves a list of available Grok models from xAI. Use this endpoint when you need to discover available models, check model capabilities, or verify which models are accessible with your API key.

  • This endpoint automatically retrieves all available Grok models accessible with your API credentials. No additional configuration is required beyond selecting this endpoint template.

This endpoint returns model metadata including model names, IDs, and other model-related information. Use this endpoint to discover available models before configuring other endpoints that require a model name. For more information about the List Models endpoint, refer to the xAI API Documentation.

Once the selected endpoint template has been configured, click the Test button to the right of the endpoint selection menu to retrieve a sample of the data that will be fetched. Sample data will be displayed in the Endpoint Test Result panel on the right, allowing you to verify that the source is configured correctly before saving.

Manual configuration

Grok by xAI data sources can also be manually configured to ingest data from any valid Grok API endpoint, including endpoints not covered by the pre-built templates, chained API calls, or custom authentication headers or request parameters. Select the Advanced tab at the top of the configuration screen, and follow the instructions in Connect to Any API to configure the API method, endpoint URL, date/time and lookup macros, path to data, metadata, and request headers.

Grok API endpoints typically follow the pattern https://api.x.ai/v1/chat/completions or https://api.x.ai/v1/models. Common response data paths include $.choices[*] for chat completions or $.models[*] for model listings.

Once all of the relevant settings have been configured, click the Create button in the upper right corner of the screen to save and create the new Grok by xAI data source. Nexla will now begin ingesting data from the configured endpoint and will organize any data that it finds into one or more Nexsets.