Contents
An AI app is usually an ordinary web app with one extra network call: your server sends the user’s message to the provider’s API and returns the answer. The hosting side is plain Node.js or Python. The parts that need care are the API key, streaming and cost.
Browser → https://ai.example.com/api/chat (your server, holds the key) → Claude or OpenAI API
Before you start
- A plan that runs Node.js or Python apps (on ArabyHost, an AI/Developer plan) with SSH.
- An API key from the provider’s console (Anthropic Console or OpenAI Platform), with a spending limit set there.
- A domain or subdomain for the app with an SSL certificate (free SSL).
1. Create the Node.js app
In cPanel open Setup Node.js App → Create Application: Node.js version 24, application mode Production, application root ai-app, application URL ai.example.com, startup file app.js. Click Create.
2. Add the key as an environment variable
On the same page, under Environment variables, add:
ANTHROPIC_API_KEY(orOPENAI_API_KEYfor OpenAI)AI_MODEL: a model ID from the provider’s documentation, for exampleclaude-opus-5-5
Never write the key in app.js, in front-end files or in any file under public_html. If a key was ever committed to Git or shipped to a browser, revoke it in the provider’s console and create a new one.
3. Install the dependencies
The top of the app’s page shows a command that enters the app’s environment. Copy it, run it over SSH, then:
cd ~/ai-app
npm install @anthropic-ai/sdk express
4. Write a minimal streaming backend
~/ai-app/app.js:
const express = require('express');
const Anthropic = require('@anthropic-ai/sdk');
const app = express();
app.use(express.json({ limit: '20kb' }));
const client = new Anthropic(); // reads ANTHROPIC_API_KEY from the environment
app.post('/api/chat', async (req, res) => {
const message = String(req.body.message || '');
if (!message || message.length > 4000) {
return res.status(400).json({ error: 'Send a message of up to 4000 characters.' });
}
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
res.setHeader('Cache-Control', 'no-cache');
try {
const stream = client.messages.stream({
model: process.env.AI_MODEL,
max_tokens: 2000, // cost cap for each reply
messages: [{ role: 'user', content: message }],
});
stream.on('text', (text) => res.write(text));
await stream.finalMessage();
res.end();
} catch (err) {
console.error(err);
if (!res.headersSent) res.status(502);
res.end('\n[The AI service is unavailable. Please try again.]');
}
});
app.use(express.static('public'));
app.listen(process.env.PORT || 3000);
Using OpenAI instead? Install openai and replace the try block’s request with the Responses API:
const OpenAI = require('openai');
const openai = new OpenAI(); // reads OPENAI_API_KEY
const stream = await openai.responses.create({
model: process.env.AI_MODEL,
input: message,
max_output_tokens: 2000,
stream: true,
});
for await (const event of stream) {
if (event.type === 'response.output_text.delta') res.write(event.delta);
}
res.end();
5. Add a small front end
~/ai-app/public/index.html reads the reply as it streams in:
<textarea id="q"></textarea> <button id="send">Send</button>
<pre id="out"></pre>
<script>
document.getElementById('send').onclick = async () => {
const out = document.getElementById('out');
out.textContent = '';
const res = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: document.getElementById('q').value }),
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
for (;;) {
const { done, value } = await reader.read();
if (done) break;
out.textContent += decoder.decode(value, { stream: true });
}
};
</script>
6. Restart and test
Click Restart on the app’s page, then test from any terminal:
curl -N -X POST https://ai.example.com/api/chat \
-H "Content-Type: application/json" \
-d '{"message":"Write one sentence about Cairo"}'
-N turns off curl’s buffering, so you see the reply arrive in pieces.
Costs and rate limits
- You pay for tokens both ways: the prompt you send (including any conversation history) and the reply. Cap replies with
max_tokensand trim long histories. - Set a spending limit in the provider’s console and watch the usage page during the first days.
- Rate limits depend on the provider and your account tier. Past the limit the API returns
429; the official SDKs retry a few times automatically, and your app should then show a friendly “try again” message (HTTP 429). - Protect your own endpoint. Without limits, anyone can call
/api/chatand spend your credit: require sign-in or limit requests per IP (for example with theexpress-rate-limitpackage), and reject very long input. - Move long jobs to the background. For tasks that take minutes, save a job record, process it in a worker kept alive by cron, and let the page poll for the result.
Troubleshooting
401or an authentication error: the variable name or the key is wrong, or the app wasn’t restarted after you added it.- The answer arrives all at once: something buffers the response. Write chunks with
res.write(), sendCache-Control: no-cache, and exclude/api/from any cache or CDN. - An application error page or 503: the app failed to start. Read the log shown on the app’s page (Passenger app error).
Cannot find module '@anthropic-ai/sdk': the packages were installed outside the app’s environment. Enter it with the command from the app’s page and install again.404or “model not found”: the ID inAI_MODELis wrong or retired. Copy a current one from the provider’s model list.- Overloaded or
5xxfrom the provider: usually temporary. Retry with a delay and show a clear message.
On ArabyHost
The AI/Developer plans run Node.js 20 and 24 and Python 3.9-3.12 apps through Setup Node.js App and Setup Python App (CloudLinux selectors with Phusion Passenger), with background workers kept alive by cron and free SSL issued automatically. Resources are per account and there’s no GPU, so the model runs at the provider and your app calls its API. Deploy from GitHub, by ZIP upload, or straight from Claude or Cursor through Araby MCP, and when something breaks, Araby AI reads your app’s error log and explains the fix. For a Node.js walkthrough without the AI parts, see Deploy a Node.js app.
FAQ
Can I call the Claude or OpenAI API directly from JavaScript in the browser?
Not with your secret key. Anything in front-end code can be read by every visitor, who could then spend your credit. Send requests to your own backend, which adds the key on the server.
How much will the API cost?
Providers bill per token, for the text you send and the text you get back, at prices that depend on the model. Check the provider's pricing page, cap replies with a token limit, and set a spending limit in the provider's console.
Can I run an open-source model on the same hosting instead?
Not on shared or developer hosting: running a language model needs a GPU and a lot of memory. Call a hosted API, or run the model on a dedicated GPU server and call it from your app.