> See the full index of documentation pages at https://docs.zettabyte.com/llms.txt.

# Quickstart: call zSTUDIO with the OpenAI SDK

> zSTUDIO's model API gives you a choice of models through one API, and you pay per token. Send one chat completion to it from Python, Node or curl, using the OpenAI SDK.

Source: https://docs.zettabyte.com/docs/maas/quickstart

Last updated: 2026-10-10

A request goes to zSTUDIO's API, which returns the reply from the model the request names. You name the model in each request, so one app or workflow can use a different model at each step, with the same code and the same API key.

To point OpenAI SDK code at zSTUDIO, you set three values: the base URL, your API key and a model ID. Every call carries all three, and each has its own job.

- Moving code that already calls OpenAI, or want the whole picture first? See the [zSTUDIO API overview](https://docs.zettabyte.com/docs/maas/overview).
- Connecting an app or tool rather than your own code? See [Connect an app or tool to zSTUDIO](https://docs.zettabyte.com/docs/maas/connect-an-app-or-tool).

## Before you begin

You need three things for the first call:

- A zSTUDIO API key. Create one with **Create API Keys** on the console's **API Keys** page (open [API Keys](https://app.zettabytecloud.com/API-key/list)); [API keys](https://docs.zettabyte.com/docs/inference-api/api-keys) walks through the form.
- A model ID, from the console, as in [Find a model ID](https://docs.zettabyte.com/docs/maas/quickstart#find-a-model-id). [zSTUDIO models and model IDs](https://docs.zettabyte.com/docs/maas/models) lists them.
- Credit on the account. A call from an account with no credit returns `403`. Credit shows as **Wallet** on the console's **Payment and Bill** page (open [Payment and Bill](https://app.zettabytecloud.com/revenue-bill-overview/list)).

> [!NOTE]
> **New to API calls?**
> Each call carries three values: your **API key**, which proves the call comes from your account; the **base URL**, the address calls go to (use it exactly as the samples write it); and the **model ID**, which names the model the call is for.

> [!NOTE]
> **New to the terminal?**
> On Windows, PowerShell opens from the Start menu: type PowerShell. A prompt that starts with `PS` is PowerShell; otherwise it's Command Prompt. The path in the prompt is the folder the terminal is in.

## Set your API key

Put your key where the samples can read it, in the terminal you'll use for every step.

Open one terminal, or your editor's built-in terminal, and keep it for the whole task. The variable, the install and the run all happen in the same one.

The samples read the key from a variable named `ZSTUDIO_API_KEY`, and pass it to the SDK explicitly. A separate name keeps this key apart from an `OPENAI_API_KEY` you may already have set, so each call uses the key you mean.

Run the line for your shell, with your key in place of `YOUR_API_KEY`.

macOS and Linux:

```bash
export ZSTUDIO_API_KEY="YOUR_API_KEY"
```

Windows PowerShell:

```powershell
$env:ZSTUDIO_API_KEY = "YOUR_API_KEY"
```

Windows Command Prompt, with no quotes around the value:

```bat
set ZSTUDIO_API_KEY=YOUR_API_KEY
```

The variable lasts until that terminal closes. To keep it set in new terminals on macOS and Linux, add the `export` line to your shell's profile file, such as `~/.zshrc`. On Windows, `setx ZSTUDIO_API_KEY "YOUR_API_KEY"` saves it for terminals you open afterwards, not the current one.

The samples read the key from the variable, not from the code file, so the key stays out of anything you share or commit the file to. Keep it out of the file, even when a sample fails.

## Find a model ID

Get the ID of the model your call is for, and put it in the samples.

[zSTUDIO models and model IDs](https://docs.zettabyte.com/docs/maas/models) lists the IDs. To see the current list, use the Model Market:

1. At the top of the console, use the workspace switcher to open the **MaaS via API** workspace. **Model Market** isn't in the default menu, and its address shows a `404` page from another workspace, so switch first.
2. In **Model Market**, open the model, then its **API & endpoint** tab. The snippet there carries the model's ID as the `model` value.
3. Copy just that value, and replace `MODEL_ID` in the samples with it.

## Install the SDK

Install the OpenAI SDK for your language, in the same terminal.

For Python, run `pip install openai`. For Node, run `npm install openai` in the folder you'll save the sample in.

**Python**

```bash
pip install openai
```

**Node**

```bash
npm install openai
```

> [!NOTE]
> **`pip` not recognised?**
> On Windows, try `py -m pip install openai` instead. On macOS, try `python3 -m pip install openai`.

## Make the call

Save a sample and run it, to send one chat completion.

Save the Python sample as `call.py`, or the Node sample as `call.mjs`, in the folder the terminal is in. Each sample's first line is a comment with its file name. The curl sample uses bash syntax, so it runs in a macOS or Linux terminal; on Windows, use the Python or Node sample.

> [!NOTE]
> **Saving with Notepad?**
> It saves as `.txt` by default, so `call.py` becomes `call.py.txt`: choose **All files** in the save dialog, or the file won't be found when you run it.

**Python**

```python
# call.py
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://app.zettabytecloud.com/inference/v1",
    api_key=os.environ["ZSTUDIO_API_KEY"],
)

completion = client.chat.completions.create(
    model="MODEL_ID",
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)

print("Reply:", completion.choices[0].message.content)
```

**Node**

```javascript
// call.mjs
import OpenAI from "openai";

const apiKey = process.env.ZSTUDIO_API_KEY;
if (!apiKey) {
  throw new Error("ZSTUDIO_API_KEY is not set.");
}

const client = new OpenAI({
  baseURL: "https://app.zettabytecloud.com/inference/v1",
  apiKey: apiKey,
});

const completion = await client.chat.completions.create({
  model: "MODEL_ID",
  messages: [{ role: "user", content: "Say hello in one sentence." }],
});

console.log("Reply:", completion.choices[0].message.content);
```

**curl**

```bash
curl https://app.zettabytecloud.com/inference/v1/chat/completions \
  -H "Authorization: Bearer $ZSTUDIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "messages": [
      {"role": "user", "content": "Say hello in one sentence."}
    ]
  }'
```

Run the file from the same terminal:

**Python**

```bash
python call.py
```

**Node**

```bash
node call.mjs
```

> [!NOTE]
> **`python` not recognised?**
> On Windows, try `py call.py` instead. On macOS, try `python3 call.py`.

## Check the response

See that the call worked.

The Python and Node samples print the model's reply on one line, after `Reply:`. The words vary with the model and the call.

What you'll see:

```text
Reply: Hello, I hope you're having a wonderful day!
```

The curl sample prints the full JSON response, with the reply text in `choices[0].message.content`.

## If the call fails

Fix the two setup errors the samples raise, and find the rest.

If the Python sample stops with `KeyError: 'ZSTUDIO_API_KEY'`, the variable isn't set in the terminal the code runs from. Set it in that terminal, as in [Set your API key](https://docs.zettabyte.com/docs/maas/quickstart#set-your-api-key), and run the file again.

If the Node sample stops with its own error, `ZSTUDIO_API_KEY is not set.`, the fix is the same.

For another error, such as a `401`, `403` or `503` status, or code that fails where it reads `choices`, look up the error your code shows in [zSTUDIO API errors](https://docs.zettabyte.com/docs/maas/errors).

## Next steps

- Connecting an app or tool instead of your own code? See [Connect an app or tool to zSTUDIO](https://docs.zettabyte.com/docs/maas/connect-an-app-or-tool).
- Want the full shape of the API, including how errors and limits work? See the [zSTUDIO API overview](https://docs.zettabyte.com/docs/maas/overview#errors-and-limits).
