01.06.2026

How to Use the Serverspace GPT API in a Python Application

Modern language models make it possible to add text generation capabilities, intelligent assistants, automated data processing, user support, and content analysis to applications. Thanks to the compatibility of the Serverspace GPT API with the OpenAI format, integration into a Python application takes only a few minutes and requires minimal code.

In this guide, we will look at connecting the Serverspace GPT API to a Python project, sending the first request, and receiving a response from the model.

What You Need Before Getting Started

Before connecting, make sure you have:

Serverspace uses an OpenAI-compatible request format and a standard endpoint for working with chat models.

Obtaining an API Key

To work with the GPT API, you need to create or copy an existing API key.

Open the GPT section in the Serverspace control panel.
Go to the API Keys tab.
Copy the generated access key.

By default, one API key is already created when using the GPT service for the first time.

Installing Required Libraries

Install the official OpenAI SDK:

pip install openai

Thanks to full compatibility with OpenAI, you can use the standard library without any additional modifications.

Creating Your First Request

Create a file main.py and add the following code:

from openai import OpenAI

client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://gpt.serverspace.io/v1"
)

response = client.chat.completions.create(
model="gpt-5.4-mini",
messages=[
{
"role": "user",
"content": "Hello! Briefly tell me about the Serverspace platform."
}
],
temperature=0.6,
max_tokens=300
)

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

Where:

The endpoint used for requests:

https://gpt.serverspace.io/v1/chat/completions

Running the Application

Run the script using the command:

python main.py

After executing the request, the model will return a response in the console:

Serverspace is a cloud platform for deploying virtual infrastructure and using modern AI models via API.

Working with System Instructions

System messages can be used to control the model’s behavior.

Example:

from openai import OpenAI

client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://gpt.serverspace.io/v1"
)

response = client.chat.completions.create(
model="gpt-5.4-mini",
messages=[
{
"role": "system",
"content": "You are a technical consultant for Linux."
},
{
"role": "user",
"content": "How do I check RAM usage in Ubuntu?"
}
]
)

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

A system message helps define the response style, constraints, and role of the model within the application.

Processing JSON Responses

The API response contains additional metadata.

Example of retrieving the full response:

from openai import OpenAI

client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://gpt.serverspace.io/v1"
)

response = client.chat.completions.create(
model="gpt-5.4-mini",
messages=[
{
"role": "user",
"content": "What is Docker?"
}
]
)

print(response.model_dump())

As a result, you will receive an object containing information about the model, token usage, and the generated message.

Practical Use Cases

Serverspace GPT API can be used for a wide range of tasks:

Thanks to OpenAI compatibility, existing projects can be adapted to the Serverspace GPT API with minimal code changes.

FAQ

Conclusion

The Serverspace GPT API allows you to quickly add artificial intelligence capabilities to Python applications. To get started, you only need to create an API key, install the OpenAI library, and set the Serverspace endpoint. Thanks to the compatible request format, integration takes just a few minutes and is suitable for both small scripts and full-scale commercial services.