Docs

Call models in the customer's cloud

This example builds a small API in the customer's cloud that calls the model service already there: Amazon Bedrock, Vertex AI, or Azure AI Foundry. Prompts never leave their account, and no provider API key exists anywhere.

Architecture diagram. Left: Your cloud, Your product. Right: Customer cloud containing api (Worker); assistant (AI); cloud model service.

The Worker calls Bedrock, Vertex AI, or Azure AI Foundry in the same account with workload identity. No API key, and prompts stay in the account.

What you build:

  • A Worker (serverless code Alien runs in the customer's account) with GET /models, which lists the models that account can use.
  • GET /ask, which sends a question to one of them with an OpenAI-style call.
  • Authorization by the Worker's own cloud identity, so no key in your code, your release, or the customer's initial setup (the one-time step their admin runs).

Source: examples/ai-quickstart-ts.

Why the customer's model service

Prompts usually carry customer records, documents, or code. Calling OpenAI or Anthropic from your servers with your key sends that data to a provider the customer didn't choose, under your contract, through your infrastructure.

Most enterprises already have a model service in their own cloud account, with terms their security team approved. An AI resource lets your code use it: you write one OpenAI-style call, and Alien routes it to that service, signed with the workload's identity.

Prompts and responses stay under the customer's data-handling terms, quotas, and billing, and never pass through your backend.

The model and the Worker

alien.ts
import * as alien from "@alienplatform/core"

// An AI model the app can call, served by the customer's own cloud; no API keys.
const assistant = new alien.AI("assistant").build()

const api = new alien.Worker("api")
  .code({ type: "source", src: "./", toolchain: { type: "typescript" } })
  .publicEndpoint("api")
  .link(assistant)
  .permissions("execution")
  .build()

export default new alien.Stack("ai-quickstart")
  .platforms(["aws", "gcp", "azure"])
  .add(assistant, "live")
  .add(api, "live")
  .permissions({
    profiles: {
      execution: {
        "*": ["ai/invoke"],
      },
    },
  })
  .build()
  • alien.AI("assistant") doesn't name a model. It means "the model service in this deployment's cloud".
  • .link(assistant) makes it available to the Worker as ai("assistant").
  • ai/invoke in the execution profile becomes the cloud permission to call it, such as Bedrock invoke permissions on AWS.
  • "live" means Alien creates both resources and updates them on every release, without the customer's admin. See Frozen and live.

The stack is limited to AWS, Google Cloud, and Azure, because those are the clouds with a built-in model service. On Kubernetes, an AI resource needs an external binding with your provider key.

List the models

Model catalogs differ by cloud, region, and account. Ask at runtime instead of hardcoding IDs:

src/index.ts
// The models this deployment's cloud actually has enabled, each with an id,
// provider, and displayName for a picker. Models not enabled on this cloud are
// absent, so call this to discover what you can use.
app.get("/models", async c => {
  const models = await ai("assistant").getAvailableModels()
  return c.json({ models })
})

getAvailableModels() returns { id, provider, displayName } for each model this deployment can call. Use it to fill a model picker, or pick one in code.

Ask a question

src/index.ts
// One-shot question -> answer. Discover then pick: `?model=` overrides, else use the
// first model getAvailableModels returned for this cloud.
app.get("/ask", async c => {
  const question = c.req.query("q")
  if (!question) {
    return c.json({ error: "pass a question as ?q=..." }, 400)
  }
  const assistant = ai("assistant")
  const model = c.req.query("model") ?? (await assistant.getAvailableModels())[0]?.id
  if (!model) {
    return c.json({ error: "no models available for this cloud" }, 500)
  }
  const completion = await assistant.chat.completions.create({
    model,
    messages: [{ role: "user", content: question }],
  })
  return c.json({ model, answer: completion.choices[0]?.message?.content ?? "" })
})

export default app

ai("assistant").chat.completions.create() takes the OpenAI Chat Completions request you already know. An AI gateway next to your Worker forwards it to the cloud's model service with the Worker's identity.

For Claude, or for other client libraries, getAiConnection("assistant") returns a baseURL you can pass to any SDK. See the AI reference.

The route returns 400 without q, and 500 if the cloud has no models enabled.

Run it locally

Your laptop has no cloud identity, so locally the binding uses a provider key you supply:

alien init ai-quickstart-ts ai-quickstart
cd ai-quickstart
OPENAI_API_KEY=sk-... alien dev

alien dev prints the Worker's URL. List the models:

curl "<url>/models"

With an OpenAI key, the local list is a short fixed set:

{
  "models": [
    { "id": "gpt-4o-mini", "provider": "openai", "displayName": "gpt-4o-mini" },
    { "id": "gpt-4o", "provider": "openai", "displayName": "gpt-4o" }
  ]
}

Ask a question:

curl "<url>/ask?q=Reply+with+exactly+one+word:+pong"
{ "model": "gpt-4o-mini", "answer": "pong" }

To use any other OpenAI-compatible server locally, such as a model on your machine, set ALIEN_AI_LOCAL_BASE_URL to its base URL.

Deploy to a customer

alien login
alien link
alien release
alien onboard customer-1 --allow admin@customer-1.com

alien onboard prints a setup link: a URL that opens the deployment portal, the setup page Alien hosts for the customer's admin. The admin opens it and runs the initial setup in their account.

After that, /models returns that account's catalog and /ask calls its model service. No key is involved at any step.

What the initial setup creates

PlatformassistantModels
AWSNothing new. The Worker's role gets access to Amazon Bedrock.Claude, GPT-5, gpt-oss, Qwen, Mistral, and other Bedrock models
Google CloudEnables the Vertex AI API and a custom prediction-only roleClaude, Gemini
AzureAn Azure AI Foundry account with gpt-4.1, gpt-4o-mini, and model-router deploymentsClaude and those three OpenAI models
alien devA binding to your provider keyWhat the key can reach

The api Worker runs as Lambda, Cloud Run, or Container Apps.

Model availability

Some models need a one-time action in the customer's cloud before they appear in getAvailableModels():

  • Amazon Bedrock: open-weight models work without activation. Claude needs the Anthropic use-case form in the Bedrock console.
  • Vertex AI: Gemini works without activation. Claude needs enabling in Model Garden, with Anthropic's terms accepted.
  • Azure AI Foundry: the GPT deployments are created for you. Claude needs Marketplace terms accepted and a deployment in the Foundry portal.

Until a model is activated it isn't listed. The deployment still succeeds, and every other model keeps working. That's why the example picks from getAvailableModels() instead of naming a model.

Before production

  • /ask is public, so anyone with the URL spends the customer's model quota. Authenticate it, or remove the public endpoint and expose the call as a command your backend invokes.
  • Pick a model deliberately. The first entry in getAvailableModels() differs by cloud and region, so store the customer's choice, for example from a picker fed by /models.
  • Retry on AI_UPSTREAM_ERROR with status 429, 502, 503, or 504, and on AI_TRANSPORT_ERROR.

Next

On this page