> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baseten.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy a model

> Run a catalog model on dedicated hardware.

Deploy Gemma 4 E2B Instruct through Explore, the Baseten CLI, or the Management API. Each path creates a dedicated endpoint that you can call from Python.

You'll need a [Baseten account](https://app.baseten.co/signup). This example uses an L4 GPU. Review [pricing](https://docs.baseten.co/deployment/resources.md#l4) before deploying; provisioned replicas incur charges even while idle.

## Deploy the model

Follow one tab. Each creates a separate deployment of the same model. Explore supplies a suggested configuration; the CLI and API use the [Gemma recipe](https://docs.baseten.co/examples/models/llm/gemma-4.md), so serving settings can differ.

> [tab] Baseten CLI
>
> ### Install and sign in
>
> > [tab] macOS or Linux
> >
> > ```bash Terminal theme={"system"}
> > brew tap basetenlabs/baseten
> > brew trust --formula basetenlabs/baseten/baseten
> > brew install baseten
> > ```
>
> > [tab] Windows
> >
> > Download and extract the Windows archive for the latest Baseten CLI release:
> >
> > ```powershell Terminal theme={"system"}
> > $release = Invoke-RestMethod https://api.github.com/repos/basetenlabs/baseten-cli/releases/latest
> > $asset = $release.assets | Where-Object { $_.name -like "*_windows_amd64.zip" }
> > Invoke-WebRequest $asset.browser_download_url -OutFile baseten.zip
> > Expand-Archive -Force baseten.zip .
> > ```
> >
> > Move `baseten.exe` to a directory on your `PATH`.
>
> For other platforms or a specific version, see the [Baseten CLI install reference](https://docs.baseten.co/reference/cli/baseten/overview.md#install).
>
> To sign in to the Baseten CLI, run the following command. The CLI opens your browser to sign in with your Baseten account and saves the session as a profile, which authenticates your CLI commands:
>
> ```bash Terminal theme={"system"}
> baseten auth login
> ```
>
> ### Prepare the configuration
>
> Create a project directory:
>
> ```bash Terminal theme={"system"}
> mkdir gemma-4-e2b
> cd gemma-4-e2b
> ```
>
> Copy `config.yaml` from the **E2B** tab of the [Gemma 4 recipe](https://docs.baseten.co/examples/models/llm/gemma-4.md) into this directory. It defines the weights, vLLM server, and L4 hardware.
>
> Accept the [model's Hugging Face terms](https://huggingface.co/google/gemma-4-E2B-it). Save a read token with access to its weights in [Baseten secrets](https://app.baseten.co/settings/secrets) as `hf_access_token`, the name used by the recipe.
>
> ### Push the configuration
>
> From the project directory, run:
>
> ```bash Terminal theme={"system"}
> baseten model push --tail --wait
> ```
>
> ```text Output excerpt theme={"system"}
>   Model:       model:gemma-4-E2B-it preset:latency (abc1d2ef)
>   Deployment:  xyz123
>   Environment: production
> ```
>
> `--tail` shows logs; `--wait` waits for **Active**. Save your model ID and continue to [call the model](#call-the-model).

> [tab] Dashboard
>
> 1. Open [Explore](https://app.baseten.co/explore), search for `Gemma`, and select **Gemma 4 E2B Instruct**.
> 2. Under **Deployment options**, select **Configure deployment** on the Dedicated deployment card.
> 3. Review the suggested L4 GPU, price per minute, and autoscaling settings.
> 4. Select **Deploy**. The dashboard shows the deployment's progress.
>
> Continue to [wait for the deployment](#wait-for-the-deployment).

> [tab] Management API
>
> ### Prepare the configuration
>
> Prepare a directory containing the **E2B** `config.yaml` from the [Gemma 4 recipe](https://docs.baseten.co/examples/models/llm/gemma-4.md). Accept the [model's Hugging Face access terms](https://huggingface.co/google/gemma-4-E2B-it) and save a read token with model access in [Baseten secrets](https://app.baseten.co/settings/secrets) as `hf_access_token`. You don't need to install either CLI.
>
> Create a personal key in [API keys](https://app.baseten.co/settings/api_keys) and set it in your terminal:
>
> ```bash macOS/Linux theme={"system"}
> export BASETEN_API_KEY="YOUR_API_KEY"
> ```
>
> ```powershell Windows theme={"system"}
> $env:BASETEN_API_KEY = "YOUR_API_KEY"
> ```
>
> A personal API key works for these steps on your own machine. For CI or shared automation that deploys models, Baseten recommends a [team API key](https://docs.baseten.co/organization/api-keys.md#choose-a-credential) with **Manage and call all team models** in the team that owns the model.
>
> ### Create the deployment
>
> Save this as `deploy.py` beside `config.yaml`. It [prepares an upload](https://docs.baseten.co/reference/management-api/models/prepare-model-upload.md), uploads the configuration using Baseten's temporary S3 credentials, and [creates the model](https://docs.baseten.co/reference/management-api/models/creates-a-model-from-a-source.md). The configuration tells Baseten where to download the weights.
>
> ```python deploy.py theme={"system"}
> import io
> import os
> from pathlib import Path
> import tarfile
>
> import boto3
> import requests
> import yaml
>
> raw_config = Path("config.yaml").read_text()
> config = yaml.safe_load(raw_config)
> deployment = {
>     "config": config,
>     "raw_config": raw_config,
>     "environment_name": "production",
> }
>
> api = requests.Session()
> api.headers["Authorization"] = f"Bearer {os.environ['BASETEN_API_KEY']}"
>
> # Validate the configuration and get temporary upload credentials.
> prepared = api.post(
>     "https://api.baseten.co/v1/prepare_model_upload",
>     json={"name": config["model_name"], "deployment": deployment},
>     timeout=60,
> )
> prepared.raise_for_status()
> upload = prepared.json()
>
> # Package this config-only project, with config.yaml at the archive root.
> archive = io.BytesIO()
> with tarfile.open(fileobj=archive, mode="w:gz") as tar:
>     tar.add("config.yaml", arcname="config.yaml")
> archive.seek(0)
>
> creds = upload["creds"]
> s3 = boto3.client(
>     "s3",
>     aws_access_key_id=creds["aws_access_key_id"],
>     aws_secret_access_key=creds["aws_secret_access_key"],
>     aws_session_token=creds["aws_session_token"],
>     region_name=upload["s3_region"],
> )
> s3.upload_fileobj(archive, upload["s3_bucket"], upload["s3_key"])
>
> # Create the model only after the upload succeeds.
> created = api.post(
>     "https://api.baseten.co/v1/models",
>     json={
>         "source": {
>             "kind": "model_archive",
>             "name": config["model_name"],
>             "s3_key": upload["s3_key"],
>             "deployment": deployment,
>         }
>     },
>     timeout=60,
> )
> created.raise_for_status()
> result = created.json()
> print("Model ID:", result["model"]["id"])
> print("Deployment ID:", result["deployment"]["id"])
> print("Status:", result["deployment"]["status"])
> ```
>
> Run it with [uv](https://docs.astral.sh/uv/getting-started/installation/), which installs the script's dependencies for this run:
>
> ```bash Terminal theme={"system"}
> uv run --with requests --with boto3 --with pyyaml deploy.py
> ```
>
> Save the IDs the script prints, then [wait for the deployment](#wait-for-the-deployment). Rerunning the script creates another model.
>
> This script packages only `config.yaml`. Include any custom code or bundled files when adapting it to another project.
>
> To deploy a model published through Baseten for Model Labs, see [Deploy a Model Labs listing](https://docs.baseten.co/examples/model-labs/deploy-a-published-model.md).
>
> > [accordion] Deploy to a specific team
> >
> > The script creates the model in the organization's default team. To choose a team, get its ID from [List teams](https://docs.baseten.co/reference/management-api/teams/lists-all-teams.md). Add `"team_id": "<team_id>"` to the prepare-upload request body, alongside `name` and `deployment`, and send the create request to [`POST /v1/teams/{team_id}/models`](https://docs.baseten.co/reference/management-api/models/creates-a-team-model-from-a-source) with the same body as the script's create request. Use the same team ID in both requests.

## Wait for the deployment

Open **Dedicated Inference** in the dashboard, select your model, and wait for **Active**. The CLI's `--wait` flag already waits for this state. If startup fails, check the deployment's build and runtime logs. For API automation, poll [Get deployment](https://docs.baseten.co/reference/management-api/deployments/gets-a-models-deployment-by-id.md) with the model and deployment IDs until `status` is `ACTIVE`.

## Call the model

Use the same [OpenAI-compatible request](https://docs.baseten.co/reference/inference-api/overview.md#openai-compatible-deployments) for any deployment path. Find your model ID in the CLI or API output, or select **Copy ID** beside the model name in the dashboard.

Create a personal key in [API keys](https://app.baseten.co/settings/api_keys) if you don't have one. Set it in the terminal where you'll run the client:

```bash macOS/Linux theme={"system"}
export BASETEN_API_KEY="YOUR_API_KEY"
```

```powershell Windows theme={"system"}
$env:BASETEN_API_KEY = "YOUR_API_KEY"
```

A personal API key works for these steps on your own machine. For applications, CI, and shared automation, use a [team API key](https://docs.baseten.co/organization/api-keys.md#choose-a-credential) scoped to the models, environments, or Model APIs that workload needs.

Save this as `chat.py` and replace `{model_id}` with your model ID:

```python chat.py theme={"system"}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://model-{model_id}.api.baseten.co/environments/production/sync/v1",
    api_key=os.environ["BASETEN_API_KEY"],
)

response = client.chat.completions.create(
    model="google/gemma-4-E2B-it",
    messages=[
        {"role": "user", "content": "Explain inference in one sentence."}
    ],
)

print(response.choices[0].message.content)
```

Run it with [uv](https://docs.astral.sh/uv/getting-started/installation/). The response wording varies:

```bash Terminal theme={"system"}
uv run --with openai chat.py
```

```text Example output theme={"system"}
Inference is the process of using a trained model to generate an output from new input.
```

The URL selects your deployed model's `production` environment. The `model` field matches the serving name in its configuration.

## Clean up

Exiting the client script doesn't stop the deployment. When you're finished testing, deactivate the deployment to release its replicas and stop its compute charges. Its endpoint stops serving requests; the model and configuration remain available for reactivation.

1. Open **Dedicated Inference** in the [dashboard](https://app.baseten.co) and select the model you created.
2. Under **Deployments**, select the deployment you used in this example.
3. Select **Deactivate deployment**, then **Yes, deactivate**.
4. Wait for the deployment's status to become **Inactive**.

See [Manage the deployment lifecycle](https://docs.baseten.co/deployment/manage/lifecycle.md#activate-a-deployment) to reactivate it later.

## Next steps

* [Configure autoscaling](https://docs.baseten.co/deployment/autoscaling/overview.md) to control replica counts and scale to zero when idle.
* [Configure a model server](https://docs.baseten.co/development/model/build-your-first-model.md) to learn how to write your own Truss configuration.
* [Add a deployment](https://docs.baseten.co/reference/management-api/deployments/adds-a-deployment-to-a-model.md) to publish another version under the existing model ID.
