PhoenixKit.Modules.AI.Endpoint (phoenix_kit v1.7.33)

Copy Markdown View Source

AI endpoint schema for PhoenixKit AI system.

An endpoint is a unified configuration that combines provider credentials, model selection, and generation parameters into a single entity. Each endpoint represents one complete AI configuration ready for making API requests.

Schema Fields

Identity

  • name: Display name for the endpoint (e.g., "Claude Fast", "GPT-4 Creative")
  • description: Optional description of the endpoint's purpose

Provider Configuration

  • provider: Provider type (currently "openrouter")
  • api_key: Provider API key
  • base_url: Optional custom base URL for the provider
  • provider_settings: Provider-specific settings (JSON)
    • For OpenRouter: http_referer, x_title headers

Model Configuration

  • model: AI model identifier (e.g., "anthropic/claude-3-haiku")

Generation Parameters

  • temperature: Sampling temperature (0-2, default: 0.7)
  • max_tokens: Maximum tokens to generate (nil = model default)
  • top_p: Nucleus sampling threshold (0-1)
  • top_k: Top-k sampling parameter
  • frequency_penalty: Frequency penalty (-2 to 2)
  • presence_penalty: Presence penalty (-2 to 2)
  • repetition_penalty: Repetition penalty (0-2)
  • stop: Stop sequences (array of strings)
  • seed: Random seed for reproducibility

Image Generation Parameters

  • image_size: Image size (e.g., "1024x1024", "1792x1024")
  • image_quality: Image quality ("standard", "hd")

Embeddings Parameters

  • dimensions: Embedding dimensions (model-specific)

Status

  • enabled: Whether the endpoint is active
  • sort_order: Display order for listing
  • last_validated_at: Last successful API key validation

Usage Examples

# Create an endpoint
{:ok, endpoint} = PhoenixKit.Modules.AI.create_endpoint(%{
  name: "Claude Fast",
  provider: "openrouter",
  api_key: "sk-or-v1-...",
  model: "anthropic/claude-3-haiku",
  temperature: 0.7
})

# Use the endpoint
{:ok, response} = PhoenixKit.Modules.AI.ask(endpoint.id, "Hello!")

Summary

Functions

Creates a changeset for endpoint creation and updates.

Returns the default base URL for a provider.

Returns image quality options for form selects.

Returns image size options for form selects.

Masks the API key for display, showing only the last 4 characters.

Returns a display label for the provider.

Returns provider options for form selects.

Returns reasoning effort options for form selects.

Checks if the endpoint has been validated recently (within the last 24 hours).

Extracts the model name without the provider prefix.

Returns the list of valid provider types.

Creates a changeset for updating the last_validated_at timestamp.

Functions

changeset(endpoint, attrs)

Creates a changeset for endpoint creation and updates.

default_base_url(arg1)

Returns the default base URL for a provider.

image_quality_options()

Returns image quality options for form selects.

image_size_options()

Returns image size options for form selects.

masked_api_key(api_key)

Masks the API key for display, showing only the last 4 characters.

provider_label(provider)

Returns a display label for the provider.

provider_options()

Returns provider options for form selects.

reasoning_effort_options()

Returns reasoning effort options for form selects.

recently_validated?(endpoint)

Checks if the endpoint has been validated recently (within the last 24 hours).

short_model_name(model)

Extracts the model name without the provider prefix.

valid_providers()

Returns the list of valid provider types.

validation_changeset(endpoint)

Creates a changeset for updating the last_validated_at timestamp.