How to Connect Bluehost AI Credits to Sim AI

This article assumes you've already set up a self-hosted Sim application as described in How to Install Sim, and have completed first-time setup using the Co-Pilot API. Once that's done, you can either ask Sim's chat to add a custom gateway and set the API key in secrets for you, or add it to a workflow manually. This article covers both.

Setup via Prompt

First, set the secret for the gateway key.

  1. In Sim, open Settings → Secrets.
  2. Add a workspace secret named:
    BLUEHOST_AI_GATEWAY_KEY
  3. Paste your AI Credits API key as its value and save it.
Warning

Never paste the raw key into a workflow. Reference the secret as {{BLUEHOST_AI_GATEWAY_KEY}} instead.

In the Sim chat, paste the following prompt when you're ready to set this up:

Set up the Bluehost AI gateway on this Sim server. Treat this as a first-time setup and drive it end to end; ask me only when you are blocked. Inputs (modify as needed, before running): - Gateway base URL: https://gateway.ai.bluehost.com - API key value: refer to the BLUEHOST_AI_GATEWAY_KEY secret - Model to setup and validate: claude-sonnet-4-6 Do this in order and report PASS/FAIL at each step: 1. Check whether a workspace secret for the gateway key already exists. If not, prompt to create it. 2. Probe the gateway and tell me which protocols it exposes. 3. Confirm that claude-sonnet-4-6 is working. 4. Give me a final verification checklist I can run after the restart.

Manual Workflow Layout

If you'd rather add this to a workflow manually, here's the reference for calling Claude through the Bluehost AI Gateway from a Sim workflow.

Create four blocks in this order:

  1. Start — accepts a string named prompt
  2. Function named escapePrompt — converts the prompt to a JSON-safe string
  3. API named gatewayCall — sends the request to the gateway
  4. Function named extractText — returns the model text, model name, and usage

Connect them linearly:

Start → escapePrompt → gatewayCall → extractText

Step 1 – Save the Gateway Key

  1. In Sim, open Settings → Secrets.
  2. Add a workspace secret named:
    BLUEHOST_AI_GATEWAY_KEY
  3. Paste your AI Credits API key as its value and save it.

Reference the secret as {{BLUEHOST_AI_GATEWAY_KEY}}. Do not paste the raw key into the workflow.

Step 2 – Configure the Start Block

  1. Add a Start block.
  2. Add an input field with these settings:
    1. Name: prompt
    2. Type: string
  3. Connect the Start block to the escapePrompt function block.

Step 3 – Add the escapePrompt Function Block

Add a JavaScript Function block, name it escapePrompt, and paste this code exactly:

// Produce a JSON-safe quoted string so it can be inlined into the request body return JSON.stringify(String(<start.prompt> ?? ''));

When entering <start.prompt>, use Sim's connection-value picker so it references the Start block's prompt output.

Tip

Why this block is required: Sim interpolates connection values into an API request body as raw text. A prompt inserted directly into JSON can make the body invalid, especially when it contains double quotes, backslashes, or newlines. JSON.stringify returns a complete JSON string literal — including surrounding quotes and the required escaping — so the value can be inserted safely. Because the function output already includes the JSON quotes, do not add quotes around <escapePrompt.result> in the API body.

Step 4 – Configure the gatewayCall API Block

Add an API block and name it gatewayCall.

Method and URL

  • Method: POST
  • URL: https://gateway.ai.bluehost.com/v1/chat/completions

Headers

Add these headers exactly:

Headers for the gatewayCall API block
Key Value
content-type application/json
Authorization Bearer {{BLUEHOST_AI_GATEWAY_KEY}}

JSON Body

Paste this body:

{ "model": "claude-sonnet-4-6", "max_tokens": 1024, "messages": [ { "role": "user", "content": <escapePrompt.result> } ] }

Use Sim's connection-value picker for <escapePrompt.result>. It must remain unquoted because the preceding function returns an already quoted and escaped JSON string literal.

Step 5 – Add the extractText Function Block

Add another JavaScript Function block, name it extractText, and paste this code exactly:

const res = <gatewayCall.data>; const text = res?.choices?.[0]?.message?.content; if (typeof text !== 'string' || text.length === 0) { throw new Error('No content in gateway response: ' + JSON.stringify(res).slice(0, 500)); } return { text, model: res.model, usage: res.usage };

Use Sim's connection-value picker for <gatewayCall.data>. The block returns:

  • text — generated assistant text
  • model — model reported by the gateway
  • usage — prompt, completion, and total token counts

Step 6 – Test the Workflow

Run the workflow with a prompt that includes quotes and, ideally, a newline. For example:

In one sentence, explain why Paris is called the "City of Light."

Confirm that:

  • all four blocks complete successfully;
  • extractText.text contains model-generated text;
  • extractText.model is claude-sonnet-4-6;
  • the API request returns HTTP 200.
Warning

If the API returns 400 Invalid JSON payload: verify that the escapePrompt block is present, that the API body uses <escapePrompt.result> rather than <start.prompt>, and that <escapePrompt.result> is not surrounded by quotation marks.

Switching Models

Change only the model field in the API block body:

"model": "claude-sonnet-4-6"

For example:

"model": "claude-opus-4-6"

Use an exact model ID returned by the gateway — see AI Models and Credit Pricing for the full list of supported model IDs and their credit cost. To list the currently available models directly from the gateway instead, send:

curl "https://gateway.ai.bluehost.com/v1/models" \ -H "Authorization: Bearer YOUR_GATEWAY_KEY"

The models endpoint also accepts Anthropic-style authentication:

curl "https://gateway.ai.bluehost.com/v1/models" \ -H "x-api-key: YOUR_GATEWAY_KEY" \ -H "anthropic-version: 2023-06-01"
Warning

Never put a real key into a workflow or shared document. The shell examples above use placeholders only; in Sim, continue using {{BLUEHOST_AI_GATEWAY_KEY}}.

Anthropic-Compatible /v1/messages Alternative

The gateway also supports Anthropic's Messages API. To use it, change the API block as follows.

Method and URL

  • Method: POST
  • URL: https://gateway.ai.bluehost.com/v1/messages

Headers

Headers for the Anthropic-compatible /v1/messages endpoint
Key Value
content-type application/json
x-api-key {{BLUEHOST_AI_GATEWAY_KEY}}
anthropic-version 2023-06-01

JSON Body

{ "model": "claude-sonnet-4-6", "max_tokens": 1024, "messages": [ { "role": "user", "content": <escapePrompt.result> } ] }

The Anthropic response shape differs from the OpenAI-compatible response. Replace the extraction function with an Anthropic-specific version if using this endpoint; assistant text is normally under content[0].text rather than choices[0].message.content.

Gateway Response Headers

The API block response includes useful Bluehost headers:

  • x-bh-model — resolved model ID used for the request. Check this to verify that the gateway did not substitute another model.
  • x-bh-cost — reported cost for the call, expressed in US dollars.

Depending on the API block output shape, headers may be available alongside the response status and body rather than inside gatewayCall.data. Inspect the API block output in the execution trace to locate them. Surface these values in a downstream Function block if model auditing or spend tracking is required.

Summary

Connecting AI Credits to Sim means either asking Sim's chat to configure the Bluehost AI Gateway end to end via a driving prompt, or building the workflow manually with four linear blocks: Start (a prompt string input), escapePrompt (JSON-safe encoding via JSON.stringify), gatewayCall (a POST to https://gateway.ai.bluehost.com/v1/chat/completions authenticated with a BLUEHOST_AI_GATEWAY_KEY secret), and extractText (pulling text, model, and usage out of the response). Switch models by changing the model field to any ID returned by GET /v1/models, or use the Anthropic-compatible /v1/messages endpoint instead if you prefer that response shape. The x-bh-model and x-bh-cost response headers let you audit which model actually ran and what it cost.