# How to Get a GPT-6 Astra API Key and Connect the Model: Pricing and Client Setup

> AI Release · @ai_release1 · https://ai-release.org/guides/kak-poluchit-api-klyuch-gpt-6-astra-i-podklyuchit-model_en.html

## TL;DR

- **Time to complete:** about 15 minutes (5 minutes to obtain the key, 10 minutes to configure and verify one client)
- **Difficulty:** Basic
- **You will need:** an account on the provider platform that serves GPT-6 Astra, a terminal (macOS/Linux shell, or Windows PowerShell 5.1+), `curl`, Python 3.9+ with `pip`, and the `openai` Python SDK 1.x or newer
- **Result:** a working `.env` with the key, a verified `curl` call, a Python client, and a CLI client all pointing at the same OpenAI-compatible endpoint

Anything marked **(check the documentation)** — base URL, exact model ID, and prices — is provider-specific and must be copied from your dashboard, not guessed.

## Requirements and setup
![Illustration: Requirements and setup](https://ai-release.org/guides/img/kak-poluchit-api-klyuch-gpt-6-astra-i-podklyuchit-model-en-1.jpg?v=1792996958)


- OS: macOS 12+, Ubuntu 20.04+, or Windows 10/11 with PowerShell
- `curl` available: `curl --version` → prints something like `curl 8.4.0`
- Python 3.9+: `python3 --version`
- The `openai` package: `python3 -m pip install --upgrade "openai>=1.0"`
- A project folder where you will store `.env`, e.g. `~/projects/astra-smoke`
- An account with an API key created in the provider console, and a payment method or credit balance if the plan is paid **(check the documentation)**
- Free disk space is irrelevant here; the SDK is small. Network access to the provider's API host is what matters — corporate proxies are the usual blocker.

**Example:** create the workspace and confirm the toolchain in one go:

```bash
mkdir -p ~/projects/astra-smoke && cd ~/projects/astra-smoke
python3 -m pip install --upgrade "openai>=1.0"
python3 -c "import openai; print(openai.__version__)"
```

Expected output is a version number such as `1.55.0`. If `pip` fails with `error: externally-managed-environment`, create a virtual environment first:

```bash
python3 -m venv .venv && source .venv/bin/activate
```

**How the request actually flows** — this is the mental model you need before configuring anything:

1. Your client reads two environment variables: `GPT6_API_KEY` (the secret) and `GPT6_BASE_URL` (the API host, for example `https://<your-api-host>/v1`).
2. It sends `POST <base-url>/chat/completions` over HTTPS with the header `Authorization: Bearer $GPT6_API_KEY`.
3. The gateway validates the key, checks your plan's quota and rate limit, then routes the request to the Astra model.
4. The response arrives as JSON: the text is in `choices[0].message.content`, and token counters are in `usage.prompt_tokens` / `usage.completion_tokens`.
5. Billing is metered from those `usage` counters, which is why you verify them in Step 3 rather than trusting the dashboard alone.

**Checklist before you start:**

- [ ] Key created and copied once (most consoles show it only at creation time)
- [ ] Base URL copied from the API reference page **(check the documentation)**
- [ ] `.env` added to `.gitignore`
- [ ] Billing/quota status confirmed in the console
- [ ] Proxy settings known: `echo $HTTPS_PROXY`

## Step 1. Obtain the API key and record the access details

**What to do:** Sign in to the provider console, open the API keys section (usually **Dashboard → API Keys → Create new secret key**), name the key something traceable like `astra-smoke-macbook`, and copy the value immediately. Then create the local config files.

**Why:** The key is shown once; if you lose it you must rotate it. Naming keys per machine lets you revoke one laptop without breaking CI.

**Example:** create `.env` in `~/projects/astra-smoke`:

```bash
GPT6_API_KEY=<your-api-key>
GPT6_BASE_URL=<your-api-base-url>
GPT6_MODEL=<model-id-from-the-models-endpoint>
```

Load it into the current shell and prove `.env` is not tracked by git:

```bash
set -a; source .env; set +a
git init -q 2>/dev/null; printf ".env\n.venv/\n" >> .gitignore
git check-ignore -v .env
```

Expected output: `.gitignore:1:.env	.env` — the rule that matches the file. If the command prints nothing and exits with code 1, the file is **not** ignored; fix `.gitignore` before the first commit.

Windows PowerShell equivalent:

```powershell
$env:GPT6_API_KEY  = "<your-api-key>"
$env:GPT6_BASE_URL = "<your-api-base-url>"
```

**How to check:** confirm the variable is set without printing the secret:

```bash
test -n "$GPT6_API_KEY" && echo "key loaded: ${#GPT6_API_KEY} chars"
curl -s -o /dev/null -w "%{http_code}\n" "$GPT6_BASE_URL/models" -H "Authorization: Bearer $GPT6_API_KEY"
```

You want `key loaded: 48 chars` (your length will differ) and `200`. A `401` means the key string is wrong or has stray whitespace; `404` usually means `GPT6_BASE_URL` is missing the version segment.

**Record the details you will need later** — fill the right column from your console, not from this guide:

| Field | Where to get it | Your value |
|---|---|---|
| Base URL | API reference page in the console **(check the documentation)** | `<your-api-base-url>` |
| API key | **Dashboard → API Keys** | stored in `.env` only |
| Model ID | output of `GET /models` (Step 2) | `<model-id-from-the-models-endpoint>` |
| Price per input/output token | pricing page **(check the documentation)** | — |
| Rate limit (requests/min, tokens/min) | plan page **(check the documentation)** | — |

Plan structure and payment methods are described in [GPT-6.1 Sol Pricing and Access: Plans and Payment Methods](https://ai-release.org/guides/skolko-stoit-gpt-6-1-sol-i-kak-poluchit-dostup-tarify-i.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide) — read it for how the vendor packages plans, then confirm the Astra numbers on your own pricing page.

## Step 2. Connect the model in your clients
![Illustration: Step 2. Connect the model in your clients](https://ai-release.org/guides/img/kak-poluchit-api-klyuch-gpt-6-astra-i-podklyuchit-model-en-2.jpg?v=1792996963)


**What to do:** Ask the API which model IDs your key can actually use, then wire that exact string into three clients: `curl`, the Python SDK, and a CLI tool that speaks the OpenAI-compatible protocol.

**Why:** Model IDs are strings, not marketing names. Copying `gpt-6-astra` from a blog post instead of from `GET /models` is the single most common cause of `model_not_found`.

**Example — list models and pick the ID:**

```bash
curl -s "$GPT6_BASE_URL/models" -H "Authorization: Bearer $GPT6_API_KEY" \
  | python3 -c "import json,sys; [print(m['id']) for m in json.load(sys.stdin)['data']]"
```

Output is one ID per line. Copy the Astra one into `GPT6_MODEL` in `.env`, reload with `set -a; source .env; set +a`.

**Example — raw HTTP call:**

```bash
curl -s "$GPT6_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $GPT6_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"'"$GPT6_MODEL"'","messages":[{"role":"user","content":"Reply with the single word: ok"}],"max_tokens":16}'
```

**Example — Python client (`client.py`):**

```python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["GPT6_API_KEY"], base_url=os.environ["GPT6_BASE_URL"])
resp = client.chat.completions.create(
    model=os.environ["GPT6_MODEL"],
    messages=[{"role": "user", "content": "Reply with the single word: ok"}],
    max_tokens=16,
)
print(resp.choices[0].message.content)
```

Run it with `python3 client.py`. The `base_url` parameter is what makes a non-OpenAI endpoint work: the SDK only swaps the host and keeps the request schema identical.

**Example — CLI client config.** Most terminal agents accept an OpenAI-compatible provider block. A minimal `config.json` looks like this:

```json
{
  "provider": "openai-compatible",
  "base_url": "<your-api-base-url>",
  "model": "<model-id-from-the-models-endpoint>",
  "api_key_env": "GPT6_API_KEY"
}
```

The `api_key_env` field keeps the secret out of the file — the tool reads the environment variable at start-up. If your tool needs the key inline instead, export it in the shell profile (`~/.zshrc`) rather than hard-coding it. For a full walkthrough of pointing a coding agent at a custom OpenAI-compatible endpoint, see [How to connect a local LLM to Claude Code: llama-server and an OpenAI-compatible API](https://ai-release.org/guides/kak-podklyuchit-lokalnuyu-model-k-claude-code-llama-ser.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide) — the endpoint configuration is the same pattern, only the host differs.

**How to check:** the Python script must print `ok`. In the raw `curl` response, confirm three keys exist:

```bash
curl -s "$GPT6_BASE_URL/chat/completions" -H "Authorization: Bearer $GPT6_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"'"$GPT6_MODEL"'","messages":[{"role":"user","content":"ping"}],"max_tokens":8}' \
  | python3 -c "import json,sys; d=json.load(sys.stdin); print(d['model'], d['usage'])"
```

Expected: your model ID followed by a dict such as `{'prompt_tokens': 8, 'completion_tokens': 1, 'total_tokens': 9}`. Numbers will vary — what matters is that `usage` is present, because that is the field billing reads.

If you have not decided between Astra and the sibling Sol model yet, compare them first in [GPT-6 Astra vs GPT-6.1 Sol: which to choose for work, chat and API](https://ai-release.org/guides/gpt-6-astra-ili-gpt-6-1-sol-chto-vybrat-dlya-raboty-cha.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide) before you hard-code IDs in production configs.

## Step 3. Verify the connection and lock the configuration
![Illustration: Step 3. Verify the connection and lock the configuration](https://ai-release.org/guides/img/kak-poluchit-api-klyuch-gpt-6-astra-i-podklyuchit-model-en-3.jpg?v=1792996974)


**What to do:** Run a smoke test that measures latency, prints the resolved model, and writes a reusable shell wrapper. Then freeze the working values so the next session starts from a known-good state.

**Why:** A single manual call proves the key works once; a script proves it works after a shell restart, which is when environment variables usually disappear.

**Example — `smoke.py`:**

```python
import os, time
from openai import OpenAI

client = OpenAI(api_key=os.environ["GPT6_API_KEY"], base_url=os.environ["GPT6_BASE_URL"])
t0 = time.time()
r = client.chat.completions.create(
    model=os.environ["GPT6_MODEL"],
    messages=[{"role": "user", "content": "ping"}],
    max_tokens=8,
)
print("model:", r.model)
print("latency_ms:", int((time.time() - t0) * 1000))
print("tokens_in:", r.usage.prompt_tokens, "tokens_out:", r.usage.completion_tokens)
```

Run `python3 smoke.py`. Success looks like three lines:

```
model: <model-id-from-the-models-endpoint>
latency_ms: 740
tokens_in: 8 tokens_out: 1
```

Your latency figure is the baseline — re-run the script after any network or proxy change and compare, because a jump from ~700 ms to multi-second values almost always means traffic is going through a different route.

**Example — persist the environment** so you do not repeat Step 1 every session:

```bash
grep -q GPT6_API_KEY ~/.zshrc || cat >> ~/.zshrc <<'EOF'
export GPT6_API_KEY="$(grep '^GPT6_API_KEY=' ~/projects/astra-smoke/.env | cut -d= -f2-)"
export GPT6_BASE_URL="<your-api-base-url>"
export GPT6_MODEL="<model-id-from-the-models-endpoint>"
EOF
```

Open a new terminal, run `python3 smoke.py` again, and confirm identical output. **How to check:** the script exits with code 0 and prints all three lines; `echo $?` right after returns `0`.

## Troubleshooting

**Problem. Every request fails with 401 right after you copied a new key**

- Error: `{"error":{"message":"Incorrect API key provided: sk-***. You can find your API key at ...","type":"invalid_request_error","code":"invalid_api_key"}}`
- Cause: the shell still holds the old value, or the `.env` line picked up a trailing space or invisible quote character.
- Solution: re-export and re-test in a fresh shell. Check for whitespace with `grep '^GPT6_API_KEY=' .env | cat -A` — a trailing `$` should be the last character before the line ends, with no spaces before it. Then run `set -a; source .env; set +a` and repeat the `/models` call.

**Problem. The key is valid but the chat call fails with a model error**

- Error: `{"error":{"message":"The model 'gpt-6-astra' does not exist or you do not have access to it.","type":"invalid_request_error","code":"model_not_found"}}`
- Cause: the ID was typed by hand or copied from a marketing page instead of `GET /models`, or the model is not enabled on your current plan.
- Solution: list the IDs and copy exactly: `curl -s "$GPT6_BASE_URL/models" -H "Authorization: Bearer $GPT6_API_KEY" | python3 -m json.tool | grep '"id"'`. If Astra is absent from the list, access is not provisioned on your account — check the plan page **(check the documentation)** before changing code.

**Problem. Calls start returning 429 after a few minutes of testing**

- Error: `{"error":{"message":"Rate limit reached for requests","type":"requests","code":"rate_limit_exceeded"}}`
- Cause: the key hit its requests-per-minute ceiling; test loops and IDE autocomplete trigger this fast.
- Solution: add exponential backoff — sleep 1 s, 2 s, 4 s between retries — and cache repeated prompts during testing. Confirm your ceiling on the plan page; do not raise concurrency until you know the number.

## Summary and next steps

You now have a key stored outside version control, a verified model ID pulled from `GET /models`, and three clients — `curl`, the Python SDK, and a CLI tool — hitting the same OpenAI-compatible endpoint with a repeatable smoke test. Next, move `GPT6_MODEL` into your app's config layer, add retry-with-backoff around the client, and track `usage` counters daily so a pricing change never surprises you.

## FAQ

**Where do I find the GPT-6 Astra API key?**
In the provider console under **Dashboard → API Keys → Create new secret key**. The value is displayed once at creation, so copy it straight into `.env`; if you lose it, delete the key and create a new one.

**How much does the GPT-6 Astra API cost?**
Pricing is per token (input and output counted separately) and is set by the provider, so the exact figures must be read from the pricing page in your console — do not rely on third-party numbers. For how this vendor structures plans and payment methods, see the pricing guide linked in Step 1.

**Does GPT-6 Astra work with the OpenAI Python SDK and other OpenAI-compatible tools?**
Yes — you only change two things: pass `base_url` to the `OpenAI()` client and use the exact model ID returned by `GET /models`. The request and response schema stays the same, which is why the same config block works in CLI agents too.

**Which model string do I put in the `model` field?**
The `id` value from `GET /models`, character for character. Marketing names and version numbers from articles are not guaranteed to be valid IDs, and a wrong string returns `model_not_found` rather than a helpful suggestion.
