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.
- In Sim, open Settings → Secrets.
- Add a workspace secret named:
BLUEHOST_AI_GATEWAY_KEY
- Paste your AI Credits API key as its value and save it.
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:
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:
- Start — accepts a string named
prompt - Function named
escapePrompt— converts the prompt to a JSON-safe string - API named
gatewayCall— sends the request to the gateway - Function named
extractText— returns the model text, model name, and usage
Connect them linearly:
Step 1 – Save the Gateway Key
- In Sim, open Settings → Secrets.
- Add a workspace secret named:
BLUEHOST_AI_GATEWAY_KEY
- 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
- Add a Start block.
- Add an input field with these settings:
- Name:
prompt - Type:
string
- Name:
- Connect the Start block to the
escapePromptfunction block.
Step 3 – Add the escapePrompt Function Block
Add a JavaScript Function block, name it escapePrompt, and paste this code exactly:
When entering <start.prompt>, use Sim's connection-value picker so it references the Start block's prompt output.
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:
| Key | Value |
|---|---|
| content-type | application/json |
| Authorization | Bearer {{BLUEHOST_AI_GATEWAY_KEY}} |
JSON Body
Paste this body:
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:
Use Sim's connection-value picker for <gatewayCall.data>. The block returns:
text— generated assistant textmodel— model reported by the gatewayusage— 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:
Confirm that:
- all four blocks complete successfully;
extractText.textcontains model-generated text;extractText.modelisclaude-sonnet-4-6;- the API request returns HTTP 200.
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:
For example:
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:
The models endpoint also accepts Anthropic-style authentication:
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
| Key | Value |
|---|---|
| content-type | application/json |
| x-api-key | {{BLUEHOST_AI_GATEWAY_KEY}} |
| anthropic-version | 2023-06-01 |
JSON Body
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.