Skip to content

Custom connection use cases ​

Overview ​

Use these examples to build a custom connection in F5 AI Security Platform. The example responses are fictional. Change the URLs and outputs expressions to match your endpoint.

Before you begin ​

Make sure you have:

  • An AI Security workspace: For an on-premises deployment, use your workspace URL. For SaaS, use your assigned URL, such as us1.calypsoai.app or eu1.calypsoai.app.
  • An account and permissions: You need login credentials and permissions to manage connections. See Connection prerequisites.
  • Endpoint details: Get the request and response formats from your provider.
  • Credentials: Enter credential values under Connection settings, not in YAML parameters or YAML template.

Examples that use apiKey set the Authorization header to the secret value. Enter the complete header value your endpoint requires as the secret. Select Custom as the authentication type to retain a header you write yourself.

Open a custom connection ​

  1. Log in to your AI Security workspace.
  2. Go to Connections.
  3. On the Models tab, select Add other providers.
  4. In Provider name, enter a provider name or select an existing one.
  5. In Model display name, enter a name for the model.

For setup steps, see Connect with a custom connection. On the Custom model connection page, select an example from this page and adapt it to your endpoint. The example URLs and responses are fictional. For block types, fields, and expressions, see Custom connection YAML reference.

For each example:

  1. Select the YAML parameters tab.
  2. Enter each parameter name in Name and its value in Value.
  3. To add another parameter, select Add parameter.
  4. Replace {} in YAML template with the example request or workflow.
  5. Adjust the request and response expressions to match your endpoint.
  6. Select the Connection settings tab.
  7. In Authentication type, select Custom.
  8. Add the secrets specified in the example using Key and Value.
  9. Select Test and connect.

The parameter lists show names and example values, not YAML to paste into a box. Replace example values with values from your provider. YAML quotes mark string values in the lists. Don't include those quotes in Value. In an apiKey secret, enter the complete Authorization header value your endpoint requires.

Call a JSON endpoint ​

This example sends a model name and prompt, then reads output from the response. Use it on the Custom model connection page you opened in Open a custom connection. The URL and model name are examples. Replace them with values from your provider. Adjust the request and response expressions to match your endpoint.

  1. Select the YAML parameters tab.

  2. In Name, enter url. In Value, enter your endpoint URL.

  3. Select Add parameter.

  4. In Name, enter model. In Value, enter your model name.

    For example, use https://llm.example.com/v1/chat for url and example-model-1 for model.

  5. In YAML template, replace {} with the following request:

    yaml
    type: request
    method: POST
    url: '{{ url }}'
    timeout: 60
    headers:
      Content-Type: application/json
      Authorization: '{{ apiKey }}'
    json: '{{ {model, input: prompt} }}'
    outputs:
      statusCode: '{{ response.statusCode }}'
      content: '{{ response.statusCode == 200 ? response.json()?.output : null }}'
      error: '{{ response.statusCode == 200 ? null : String.decode(response.body) }}'

    If your endpoint accepts only an input field, omit the model parameter and replace the json line with:

    yaml
    json: '{{ {input: prompt} }}'
  6. Select the Connection settings tab.

  7. In Authentication type, select Custom.

  8. In Key, enter apiKey.

  9. In Value, enter the complete Authorization header value.

  10. Select Test and connect.

For the required outputs, see Custom connection YAML reference.

Retry on rate limits and server errors ​

This example wraps the JSON request in a retry block. It runs up to three times and waits 2 seconds after the first attempt and 4 seconds after the second. On the Custom model connection page, add the url and model parameters under YAML parameters. Use your endpoint URL and model name, as in Call a JSON endpoint. In YAML template, replace {} or the existing request with this block:

yaml
type: retry
attempts: 3
backoff: '{{ 2 * attempt }}'
when: '{{ Array.contains([429, 500, 502, 503, 504], statusCode) }}'
block:
  type: request
  method: POST
  url: '{{ url }}'
  timeout: 60
  headers:
    Content-Type: application/json
    Authorization: '{{ apiKey }}'
  json: '{{ {model, input: prompt} }}'
  outputs:
    statusCode: '{{ response.statusCode }}'
    content: '{{ response.statusCode == 200 ? response.json()?.output : null }}'
    error: '{{ response.statusCode == 200 ? null : String.decode(response.body) }}'

For an endpoint that accepts only input, use the alternative json line from Call a JSON endpoint. Under Connection settings, select Custom and add the apiKey secret. Enter the complete Authorization header value in Value, then select Test and connect.

Send conversation history ​

This example turns each pair in memory into a user message and an assistant message. The example endpoint returns {"reply": {"text": "..."}}.

On the Custom model connection page, select the YAML parameters tab. Add these parameters using Name and Value:

yaml
url: https://llm.example.com/v1/messages
systemPrompt: You are a helpful assistant.

In YAML template, replace {} or the existing request with this block:

yaml
type: request
method: POST
url: '{{ url }}'
timeout: 60
headers:
  Content-Type: application/json
  Authorization: '{{ apiKey }}'
json: >-
  {{ {
    messages: [
      {role: 'system', content: systemPrompt},
      ...Array.flatMap(turn => [{role: 'user', content: turn[0]}, {role: 'assistant', content: turn[1]}], memory),
      {role: 'user', content: prompt}
    ]
  } }}
outputs:
  statusCode: '{{ response.statusCode }}'
  content: '{{ response.json()?.reply?.text }}'
  error: '{{ response.statusCode == 200 ? null : String.decode(response.body) }}'

Under Connection settings, select Custom and add the apiKey secret. Enter the complete Authorization header value in Value, then select Test and connect.

Use the YAML block scalar marker >- to split an expression across lines. If your endpoint takes one string instead of a list, use String.formatChat(prompt, memory). The function returns the conversation as lines that start with user: and assistant:.

Run two requests in order ​

This workflow creates a session, then sends it a prompt. The workflow outputs pass the required values to the top level.

On the Custom model connection page, select the YAML parameters tab. Add this parameter using Name and Value:

yaml
baseUrl: https://llm.example.com

In YAML template, replace {} or the existing request with this block:

yaml
type: workflow
stages:
  - type: request
    method: POST
    url: '{{ baseUrl }}/v1/sessions'
    headers:
      Authorization: '{{ apiKey }}'
    json: '{{ {} }}'
    outputs:
      sessionId: '{{ response.json()?.id }}'
  - type: request
    method: POST
    url: '{{ baseUrl }}/v1/sessions/{{ sessionId }}/messages'
    headers:
      Authorization: '{{ apiKey }}'
    json: '{{ {text: prompt} }}'
    outputs:
      statusCode: '{{ response.statusCode }}'
      content: '{{ response.json()?.answer }}'
      error: '{{ response.statusCode == 200 ? null : String.decode(response.body) }}'
outputs:
  statusCode: '{{ statusCode }}'
  content: '{{ content }}'
  error: '{{ error }}'

Under Connection settings, select Custom and add the apiKey secret. Enter the complete Authorization header value in Value, then select Test and connect.

Read a streaming response ​

This example reads a server-sent events stream. Each event contains JSON with a delta field. The content output joins those values. Events that aren't JSON, such as [DONE], add nothing.

On the Custom model connection page, select the YAML parameters tab. Add this parameter using Name and Value:

yaml
url: https://llm.example.com/v1/stream

In YAML template, replace {} or the existing request with this block:

yaml
type: request
method: POST
url: '{{ url }}'
timeout: 300
headers:
  Accept: text/event-stream
  Authorization: '{{ apiKey }}'
json: '{{ {input: prompt, stream: true} }}'
outputs:
  statusCode: '{{ response.statusCode }}'
  content: >-
    {{ response.statusCode == 200
      ? Array.reduce((text, event) => text + (event.json()?.delta ?? ''), '', response.events())
      : null }}
  error: '{{ response.statusCode == 200 ? null : String.decode(response.body) }}'

Under Connection settings, select Custom and add the apiKey secret. Enter the complete Authorization header value in Value, then select Test and connect.

The platform reads the whole stream before it returns the reply.

Send query parameters ​

This example sends the prompt in a GET query string. The platform URL-encodes each value in queryParams.

On the Custom model connection page, select the YAML parameters tab. Add these parameters using Name and Value:

yaml
url: https://llm.example.com/v1/search
apiVersion: '2024-10-01'

In YAML template, replace {} or the existing request with this block:

yaml
type: request
method: GET
url: '{{ url }}'
headers:
  Authorization: '{{ apiKey }}'
queryParams:
  q: '{{ prompt }}'
  api-version: '{{ apiVersion }}'
outputs:
  statusCode: '{{ response.statusCode }}'
  content: '{{ response.json()?.result }}'
  error: '{{ response.statusCode == 200 ? null : String.decode(response.body) }}'

Under Connection settings, select Custom and add the apiKey secret. Enter the complete Authorization header value in Value, then select Test and connect.

Send a form-encoded body ​

Use body for a form-encoded request and set Content-Type to application/x-www-form-urlencoded. The platform doesn't URL-encode values in body. If a value can contain reserved characters such as & or =, encode it before you store it.

For a standard OAuth 2.0 client credentials flow, select OAuth 2.0 under Authentication type. The platform then caches the token. Use a workflow for token requests only if your endpoint needs a request that OAuth 2.0 doesn't send.

This example requests a token for every prompt, then passes the token as the complete Authorization header value. Use it only if the token response contains the complete header value that your model endpoint requires.

On the Custom model connection page, select the YAML parameters tab. Add these parameters using Name and Value:

yaml
url: https://llm.example.com/v1/chat
tokenUrl: https://auth.example.com/oauth/token

In YAML template, replace {} or the existing request with this block:

yaml
type: workflow
stages:
  - type: request
    method: POST
    url: '{{ tokenUrl }}'
    headers:
      Content-Type: application/x-www-form-urlencoded
    body: 'grant_type=client_credentials&client_id={{ clientId }}&client_secret={{ clientSecret }}'
    outputs:
      token: '{{ response.json()?.access_token }}'
  - type: request
    method: POST
    url: '{{ url }}'
    headers:
      Authorization: '{{ token }}'
    json: '{{ {input: prompt} }}'
    outputs:
      statusCode: '{{ response.statusCode }}'
      content: '{{ response.json()?.output }}'
      error: '{{ response.statusCode == 200 ? null : String.decode(response.body) }}'
outputs:
  statusCode: '{{ statusCode }}'
  content: '{{ content }}'
  error: '{{ error }}'

Under Connection settings, select Custom. In Key, enter clientId. In Value, enter your client ID. Select Add new secret. In Key, enter clientSecret. In Value, enter your client secret. Select Test and connect.

Start from an example configuration ​

On the Custom model connection page, select the Connection settings tab. In Example configuration, select an item to see a complete template. The list includes built-in provider templates.

Example configurationEndpoint
openai-compatible-chatOpenAI Chat Completions format
anthropicAnthropic Messages API, as a workflow block
bedrock-converseAmazon Bedrock Converse API, with an awsAuth block
azure-openai-chatAzure OpenAI deployments
google-generate-contentGoogle Gemini generateContent API

Troubleshooting ​

For common errors and fixes, see Troubleshooting a connection.

References ​

Updated at: