# Model API setup

Model-based notebooks send prompts to a configured model provider. The MCP lab, local A2A adapter, and trust-weight lab need no model key.

Single-provider model labs default to **DeepSeek**. The teaching adapter supports multiple providers.

## Initial Colab setup

1. Open the notebook in Colab and save a copy.
2. In Colab’s **Secrets** panel, create the secret for your selected provider and grant notebook access. Never paste a key into a code cell.
3. Choose the provider in the setup cell, run setup, then run the examples in order.

```python
PROVIDER = "deepseek"  # or "gemini" or "freeinference"
ask = make_ask(provider=PROVIDER)
```

The default DeepSeek provider uses `https://api.deepseek.com/v1`, model `deepseek-flash`, and secret `DEEPSEEK_API_KEY`. FreeInference uses `https://freeinference.org/v1`, model `qwen3.6-35b`, and `FREEINFERENCE_API_KEY`. See *Prompting and reasoning* below for Lab 01. If no Colab secret is available, the helper uses a hidden input prompt. Check current access and quotas in the [FreeInference documentation](https://doc.freeinference.org/).

## Use another compatible service

Pass the chosen service settings to the same helper:

```python
ask = make_ask(base_url="https://gateway.example/v1",
               model="your-model", secret_name="YOUR_SECRET_NAME", extra_body={})
```

Use a base URL including its API prefix, such as `/v1`, without `/chat/completions`. The example URL above is a placeholder. `extra_body={}` removes DeepSeek-specific options; add only settings supported by your gateway.

The helper uses the [Chat Completions request format](https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create). If a provider requires `max_completion_tokens`, add `token_field="max_completion_tokens"` to `make_ask(...)`.

Services with deployment-specific URLs, native Gemini/Messages APIs, SSO-only authentication, or custom headers may require a transport change. Use the endpoint and approved models supplied by your institution when required.

## Providers and the council

`make_ask` knows three providers. Each one fills in its base URL, default model, and Colab Secret name:

| Provider | Default model (family) | Colab Secret | Notes |
| --- | --- | --- | --- |
| `freeinference` | `qwen3.6-35b` (Qwen) | `FREEINFERENCE_API_KEY` | The free tier takes one request at a time. |
| `gemini` | `gemini-3.5-flash` (Gemini) | `GEMINI_API_KEY` | Uses Google's OpenAI-compatible endpoint, with `reasoning_effort: "minimal"`. |
| `deepseek` | `deepseek-flash` (DeepSeek) | `DEEPSEEK_API_KEY` | Default for single-provider labs; sends `thinking: disabled`. |

```python
ask = make_ask(provider="gemini")
ask = make_ask(provider="deepseek", model="deepseek-v4-pro")  # another model from the same provider
```

The presets configure a small output budget and provider-specific reasoning settings. Model identifiers and accepted settings can change; verify current availability with student-equivalent access before teaching, and override the model and `extra_body` when your institution supplies different settings.

### Choose DeepSeek or Gemini in any model lab

In a model lab’s setup cell, choose one provider and give Colab access to the matching secret. Most labs use the following setup; Lab 01 sets up separate clients for its reasoning comparison:

```python
PROVIDER = "deepseek"  # Colab Secret: DEEPSEEK_API_KEY
ask = make_ask(provider=PROVIDER)
```

Or use `PROVIDER = "gemini"` with `GEMINI_API_KEY`. You do not need a FreeInference key when using either directly. These presets use the providers' [OpenAI-compatible DeepSeek API](https://api-docs.deepseek.com/) and [Google compatibility endpoint](https://aistudio.google.com/docs/openai).

Lab 06's council needs at least three model families, so its architects use all three providers: Qwen on FreeInference, DeepSeek, and Gemini. Save all three keys in Colab Secrets.

## DeepSeek Harness preview (Lab 00)

Lab 00 includes an optional DeepSeek Harness example using the preview `deepseek-harness-sdk`. When students opt in with `RUN_HARNESS=True`, it installs its runtime, requires `DEEPSEEK_API_KEY`, and uses a temporary workspace with model-facing shell, file and working-directory tools disabled. Session-log and package-inventory uploads are disabled in the example. The runtime is separate from a direct API client and may incur additional model usage. The temporary workspace is not a security sandbox.

## Prompting and reasoning (Lab 01)

Lab 01 defaults to DeepSeek and uses `DEEPSEEK_API_KEY`; its earlier-model comparison downloads the small SmolLM2 model from Hugging Face and runs it on CPU. The final step calls `deepseek-flash` with thinking disabled and enabled using the same direct questions. The modes may differ in latency and token use; neither is guaranteed correct. The older model differs in age, size and training, so its comparison is not a controlled test of thinking mode. The old `deepseek-chat` and `deepseek-reasoner` names are retired.

## TypeSafe scores (Lab 17)

The first matrix uses explicitly illustrative numbers. Steps 4–5 use the pinned TypeSafe SDK and System One endpoint to obtain model scores, so add `TYPESAFE_API_KEY` to Colab Secrets. `coursekit.secret` reads the Colab secret or falls back to hidden local input. FreeInference credentials cannot authenticate TypeSafe.

The state describes task-queue versus event-log choices and eight option–criterion questions. TypeSafe returns typed scores; Python owns weighting and eligibility. Confidence describes the returned distribution, not a guarantee of good architecture. See the [Score](https://docs.typesafe.ai/primitives/score) and [Python SDK](https://docs.typesafe.ai/sdk/python) references.

## Optional: LangSmith traces (Lab 07)

Lab 07 can send a trace of each council run to [LangSmith](https://smith.langchain.com/). Create a free account and an API key, save it in Colab Secrets as `LANGSMITH_API_KEY`, and set `LANGSMITH_TRACING="true"` before the first step, as the lab shows. Without the key, nothing is sent, and the lab runs on its logs alone. A trace contains the case and every agent's reply, so do not trace private data to a shared project.

## Calls, errors, and limits

The example client uses HTTPS, a timeout, bounded calls/output, and no silent retry or credential switching. It keeps usage unknown when the provider does not report it. FreeInference requests are non-streaming; provider-specific settings remain separate from the general interface. A cold-start placeholder should be treated as a request to wait and retry manually, not as a useful answer.

| Symptom | Check |
| --- | --- |
| 401/403 | Key validity, secret permission, and model access |
| 404 | API prefix, base URL, and model identifier |
| 400 | Supported parameters, token field, and message roles |
| 429 | Current quota and rate limits; FreeInference's free tier allows one request at a time |
| Empty or truncated answer | Response content and output-token budget |
| Invalid JSON or unsupported citation | Model output and validation; do not bypass the check |

The setup cell installs the shared course package from a pinned public GitHub revision. Protocol and framework labs also install their relevant SDK. This needs internet access; the small MCP/A2A examples themselves do not require a model key. Runtime and server setup code is in the package rather than embedded in each notebook.

Automated verification compiles every notebook and executes the model-free local protocol and trust-weight labs without model calls. Test live-provider compatibility separately with a small request before teaching. See [Google’s Colab FAQ](https://research.google.com/colaboratory/faq.html) for notebook/runtime details.


## Lecture-aligned examples

Labs 00–17 use self-contained microservices and DDD scenarios. The A2A lab (13) uses a deterministic local payment adapter, so it no longer needs a model key. Lab 17 requires a **TypeSafe** key for model scoring. FreeInference credentials cannot be used as TypeSafe credentials. Lab 01 uses DeepSeek for its thinking-mode comparison; no OpenRouter account is required.
