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

# Make your first API call

> Create a ScitiX API key, send a Chat Completions request with Python or curl, and check the response, usage, and cost.

Send a Chat Completions request and read the model's answer. This guide covers API key setup, a non-streaming request using either the OpenAI Python SDK or curl, and where to check usage and cost.

## Before you begin

* Have a ScitiX account and access to the console.
* Choose a model in [Models](https://console.scitix.ai/model-inference/models). Check its model ID, supported capabilities, and price. The examples use `zai-org/glm-5.3`; to use another model, replace it with the ID from that model's details page.
* For Python, use Python 3.10 or later and the OpenAI Python SDK. For REST requests, use curl.

> [!WARNING]
>
> API requests incur charges. Check the model's prices before sending a request. For billing items and how tokens are counted, see [Token usage and billing](https://docs.scitix.ai/model-inference/usage/billing.md).

If you need help choosing a model, see [Choose and test a model](https://docs.scitix.ai/model-inference/get-started/model-selection-playground.md). Testing in the Playground is optional, not a prerequisite for API access.

## 1. Create an API key

1. Sign in to the console, open [**API Keys**](https://console.scitix.ai/model-inference/api_keys), and select **Create API Key**.
2. Give the key a recognizable name and copy the generated key.
3. In the terminal where you will run the examples, set the environment variable below. Replace `YOUR_API_KEY` with your key, and run subsequent commands in the same terminal.

   ```bash theme={null}
   export API_KEY="YOUR_API_KEY"
   ```

The variable is available only in that terminal session. Set it again when you open a new terminal. To load it automatically, you can add the command to your shell's user startup file. That file stores the key in plaintext; do not share it or commit it to a repository.

> [!WARNING]
>
> Do not hard-code API keys, commit them to Git, or expose them in browser or other client-side code.

The key list shows creation time, last-used time, and rate limits. To set spending caps, adjust rate limits, or manage a key's status, see [Manage API keys](https://docs.scitix.ai/model-inference/usage/api-keys.md).

## 2. Send a request

Choose Python to call the model from a program, or curl to send a REST request without installing an SDK. Both examples wait for generation to finish and then return the complete response.

| Connection detail | Value |
| - | - |
| API key | The `API_KEY` environment variable. The Python SDK reads it from the environment; the REST request sends it in `Authorization: Bearer $API_KEY`. |
| Python SDK `base_url` | `https://api.scitix.ai/model-api`. Do not include `/chat/completions`; the SDK appends the request path. |
| Full REST request URL | `https://api.scitix.ai/model-api/chat/completions`. This includes the path for the request below. |
| Model ID | `zai-org/glm-5.3`, passed in the `model` parameter. |

> [tab] Python SDK
>
> Install the OpenAI Python SDK:
>
> ```bash theme={null}
> python3 -m pip install --upgrade openai
> ```
>
> Save this example as `first_api_call.py`. It reads your API key from the environment and prints the model's final answer.
>
> ```python theme={null}
> import os
> from openai import OpenAI
>
> client = OpenAI(
>     api_key=os.environ["API_KEY"],
>     base_url="https://api.scitix.ai/model-api",
> )
>
> response = client.chat.completions.create(
>     model="zai-org/glm-5.3",
>     messages=[
>         {
>             "role": "user",
>             "content": "What new opportunities might reasoning models bring to the market?",
>         }
>     ],
>     max_completion_tokens=1024,
>     stream=False,
> )
>
> print(response.choices[0].message.content)
> ```
>
> Run the script in the terminal where you set `API_KEY`:
>
> ```bash theme={null}
> python3 first_api_call.py
> ```
>
> On success, the terminal prints the final answer from `response.choices[0].message.content`. The wording depends on the model's response.
>
> If you see `KeyError: 'API_KEY'`, set the environment variable in this terminal before running the script again. For other errors, see [Troubleshoot a failed request](#troubleshoot-a-failed-request).

> [tab] REST (curl)
>
> Run this command in the terminal where you set `API_KEY`:
>
> ```bash theme={null}
> curl https://api.scitix.ai/model-api/chat/completions \
>   -H "Authorization: Bearer $API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "zai-org/glm-5.3",
>     "stream": false,
>     "max_completion_tokens": 1024,
>     "messages": [
>       {"role": "user", "content": "What new opportunities might reasoning models bring to the market?"}
>     ]
>   }'
> ```
>
> On success, the terminal displays a JSON response. Read the final answer from `choices[0].message.content`; its wording depends on the model's response. If the response contains an error, see [Troubleshoot a failed request](#troubleshoot-a-failed-request).

### Request parameters

| Parameter | Purpose |
| - | - |
| `model` | The model ID to call. Check the model details page for supported capabilities and parameters. |
| `messages` | The messages sent to the model. In this example, `role` identifies a user message and `content` contains the prompt. |
| `max_completion_tokens` | The generation budget for this request. The example uses `1024`; adjust it as needed. For reasoning models, reasoning tokens and visible output tokens share this budget. |
| `stream` | Whether to stream the response. These examples use `false` in JSON and `False` in Python to return the complete response after generation finishes. |

To display the answer as it is generated, see [Streaming](https://docs.scitix.ai/model-inference/models/streaming.md). To read a model's reasoning output, see [Reasoning](https://docs.scitix.ai/model-inference/models/reasoning.md).

## 3. Check usage and cost

After a successful call, open [**Usage Detail**](https://console.scitix.ai/model-inference/usage_detail) in the console. Filter by model, API key, and time range to find the request and review its token usage and cost. See [View usage](https://docs.scitix.ai/model-inference/usage/view-usage.md) for details.

## Troubleshoot a failed request

First check the connection details above. Do not use the full REST request URL as the Python SDK's `base_url`. Then follow the error message:

| Symptom or HTTP status | What to check or do |
| - | - |
| Python reports `KeyError: 'API_KEY'` | Set `API_KEY` in the same terminal where you run the script. |
| `401`: authentication failed | Check that the API key is correct, usable, and included in the request. |
| `400` / `422`: invalid request | Check the model ID, request body, and model-specific parameter requirements. Correct the request before trying again. |
| `402`: billing rejected | Check the account quota and spending limits. Resolve the billing issue before trying again. |
| `429`: rate limit reached | Reduce the request rate or concurrency and wait before retrying. If the response includes `retry_after_sec`, wait at least that many seconds. |
| `500` / `502` / `503`: temporary service issue | Retry later with backoff. |

For more error types, see [Error handling](https://docs.scitix.ai/model-inference/api/error-handling.md). If the issue persists, keep the `request_id`, `traceId`, request time, model ID, and API path for technical support. Do not include your API key.

## Next steps

Choose the capabilities your application needs, and check the model details page for support:

* [Text generation](https://docs.scitix.ai/model-inference/models/text-generation.md) for text responses and multi-turn conversations.
* [Structured output](https://docs.scitix.ai/model-inference/models/structured-output.md) for extracting fields and returning a specified structure.
* [Function calling](https://docs.scitix.ai/model-inference/models/function-calling.md) for letting a model ask your application to call a tool.
* [Vision and multimodal](https://docs.scitix.ai/model-inference/models/vision-and-multimodal.md) for image and other multimodal inputs.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.