Public preview: This API is in public preview. Endpoints, schemas, and limits may change before general availability.
Your first request
Step-by-step walkthroughs in curl, JavaScript, and Python — and how to read each response.
This guide walks through one complete request end-to-end, in three languages. You will set up the environment, send the request, and parse the response.
Setup#
You need:
- An EU GPT API key (see Authentication).
- Credit on your prepaid balance (see Usage limits & billing). Without it, requests return
402. - The key exported as
EUGPT_API_KEYso the snippets below pick it up without inlining it.
export EUGPT_API_KEY="eugpt_..."
Non-streaming: ask one question, get one answer#
The simplest possible request. stream: false returns one JSON document; no SSE parsing required.
curl https://api.eugpt.ai/v1/responses \
-H "Authorization: Bearer $EUGPT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"input": "Explain the EU AI Act in three short bullets.",
"stream": false
}'import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.EUGPT_API_KEY,
baseURL: "https://api.eugpt.ai/v1",
});
const response = await client.responses.create({
model: "auto",
input: "Explain the EU AI Act in three short bullets.",
stream: false,
});
console.log(response.output_text);import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["EUGPT_API_KEY"],
base_url="https://api.eugpt.ai/v1",
)
response = client.responses.create(
model="auto",
input="Explain the EU AI Act in three short bullets.",
stream=False,
)
print(response.output_text)The shape of the JSON body is documented in Create a response.
Streaming: render output as it arrives#
For anything user-facing, stream. The first words arrive while the rest of the answer is still being written, and tool activity such as a web search shows up as it happens.
curl -N https://api.eugpt.ai/v1/responses \
-H "Authorization: Bearer $EUGPT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"input": "Write a long-form explanation of data sovereignty."
}'const stream = await client.responses.create({
model: "auto",
input: "Write a long-form explanation of data sovereignty.",
stream: true,
});
for await (const event of stream) {
if (event.type === "response.output_text.delta") {
process.stdout.write(event.delta);
} else if (event.type === "response.completed") {
process.stdout.write("\n");
}
}stream = client.responses.create(
model="auto",
input="Write a long-form explanation of data sovereignty.",
stream=True,
)
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
elif event.type == "response.completed":
print()Adding a system prompt#
instructions steers tone, format, and persona.
const response = await client.responses.create({
model: "auto",
input: "Summarise the GDPR.",
instructions: "Respond in Dutch. Use exactly five bullet points.",
stream: false,
});
The instructions apply to this response. EU GPT gives them priority over the instructions of the conversation or agent.
Continuing a conversation#
To build on earlier turns, pass the conversation_id of an existing conversation. The API does not return the id of the conversation a stateless request creates, so take the id of a conversation from the web app: open it, and copy the last part of the address (chat.eugpt.ai/chats/<conversation id>). See Conversations.
const followUp = await client.responses.create({
model: "auto",
conversation_id: "8f14e45f-ceea-467a-a4ed-a9e9a5cb16ee",
input: "Now expand step 3 into substeps.",
stream: false,
});
EU GPT adds the conversation’s earlier messages as context, and the new turn appears in the web app.
Error handling#
Requests that EU GPT refuses come back as HTTP errors, which the SDK throws. Status codes you should plan for: 400, 401, 402, 403, 404, 422, 5xx. See Errors for the payloads and retry guidance.
try {
const response = await client.responses.create({ /* … */ stream: false });
return response.output_text;
} catch (err) {
if (err.status === 402) {
// The prepaid balance is empty. Alert someone to add credit; do not retry.
} else if (err.status >= 500) {
// Transient. Retry with exponential backoff.
} else {
// Something in the request or the key. Surface to the caller.
throw err;
}
}
Next steps#
- Handling streams — parsing without an SDK, custom event handling.
- Tool use — what to do when the model decides to call
web_search. - Models — choosing and switching models.