Skip to main content
Version: 1.0

aixplain.modules.model.integration

AuthenticationSchema Objects

class AuthenticationSchema(Enum)

[view_source]

Enumeration of supported authentication schemes for integrations.

This enum defines the various authentication methods that can be used when connecting to external services through integrations.

Attributes:

  • BEARER_TOKEN str - Bearer token authentication scheme.
  • OAUTH1 str - OAuth 1.0 authentication scheme.
  • OAUTH2 str - OAuth 2.0 authentication scheme.
  • API_KEY str - API key authentication scheme.
  • BASIC str - Basic authentication scheme (username/password).
  • NO_AUTH str - No authentication required.

BaseAuthenticationParams Objects

class BaseAuthenticationParams(BaseModel)

[view_source]

Base model for authentication parameters used in integrations.

This class defines the common parameters that are used across different authentication schemes when connecting to external services.

Attributes:

  • name Optional[Text] - Optional name for the connection. Defaults to None.
  • connector_id Optional[Text] - Optional ID of the connector. Defaults to None.

build_connector_params

def build_connector_params(**kwargs) -> BaseAuthenticationParams

[view_source]

Build authentication parameters for a connector from keyword arguments.

This function creates a BaseAuthenticationParams instance from the provided keyword arguments, extracting the name and connector_id if present.

Arguments:

  • **kwargs - Arbitrary keyword arguments. Supported keys:
    • name (Optional[Text]): Name for the connection
    • connector_id (Optional[Text]): ID of the connector

Returns:

  • BaseAuthenticationParams - An instance containing the extracted parameters.

Example:

>>> params = build_connector_params(name="My Connection", connector_id="123") >>> print(params.name) 'My Connection'

Integration Objects

class Integration(Model)

[view_source]

__init__

def __init__(id: Text,
name: Text,
description: Text = "",
api_key: Optional[Text] = None,
supplier: Union[Dict, Text, Supplier, int] = "aiXplain",
version: Optional[Text] = None,
function: Optional[Function] = None,
is_subscribed: bool = False,
cost: Optional[Dict] = None,
function_type: Optional[FunctionType] = FunctionType.INTEGRATION,
**additional_info) -> None

[view_source]

Initialize a new Integration instance.

Arguments:

  • id Text - ID of the Integration.
  • name Text - Name of the Integration.
  • description Text, optional - Description of the Integration. Defaults to "".
  • api_key Text, optional - API key for the Integration. Defaults to None.
  • supplier Union[Dict, Text, Supplier, int], optional - Supplier of the Integration. Defaults to "aiXplain".
  • version Text, optional - Version of the Integration. Defaults to "1.0".
  • function Function, optional - Function of the Integration. Defaults to None.
  • is_subscribed bool, optional - Whether the user is subscribed. Defaults to False.
  • cost Dict, optional - Cost of the Integration. Defaults to None.
  • function_type FunctionType, optional - Type of the function. Must be FunctionType.INTEGRATION. Defaults to FunctionType.INTEGRATION.
  • name0 - Any additional Integration info to be saved.

Raises:

  • name1 - If function_type is not FunctionType.INTEGRATION.

connect

def connect(authentication_schema: AuthenticationSchema,
args: Optional[BaseAuthenticationParams] = None,
data: Optional[Dict] = None,
**kwargs) -> ModelResponse

[view_source]

Connect to the integration using the specified authentication scheme.

This method establishes a connection to the integration service using the provided authentication method and credentials. The required parameters vary depending on the authentication scheme being used.

Arguments:

  • authentication_schema AuthenticationSchema - The authentication scheme to use (e.g., BEARER_TOKEN, OAUTH1, OAUTH2, API_KEY, BASIC, NO_AUTH).
  • args Optional[BaseAuthenticationParams], optional - Common connection parameters. If not provided, will be built from kwargs. Defaults to None.
  • data Optional[Dict], optional - Authentication-specific parameters required by the chosen authentication scheme. Defaults to None.
  • **kwargs - Additional keyword arguments used to build BaseAuthenticationParams if args is not provided. Supported keys:
    • name (str): Name for the connection
    • connector_id (str): ID of the connector

Returns:

  • ModelResponse - A response object containing:
    • data (Dict): Contains connection details including:
    • id (str): Connection ID (can be used with ModelFactory.get(id))
    • redirectURL (str, optional): URL to complete OAuth authentication (only for OAuth1/OAuth2)

Raises:

  • ValueError - If the authentication schema is not supported by this integration or if required parameters are missing from the data dictionary.

Examples:

Using Bearer Token authentication: >>> integration.connect( ... AuthenticationSchema.BEARER_TOKEN, ... data={"token": "1234567890"}, ... name="My Connection" ... )

Using OAuth2 authentication: >>> response = integration.connect( ... AuthenticationSchema.OAUTH2, ... name="My Connection" ... ) >>> # For OAuth2, you'll need to visit the redirectURL to complete auth >>> print(response.data.get("redirectURL"))

Using API Key authentication: >>> integration.connect( ... AuthenticationSchema.API_KEY, ... data={"api_key": "your-api-key"}, ... name="My Connection" ... )

__repr__

def __repr__()

[view_source]

Return a string representation of the Integration instance.

Returns:

  • str - A string in the format "Integration: <name> by <supplier> (id=<id>)". If supplier is a dictionary, uses supplier['name'], otherwise uses supplier directly.