Text Generation
Last updated
Was this helpful?
Was this helpful?
# Python example to retrieve available models
import requests
IONOS_API_TOKEN = "[YOUR API TOKEN HERE]"
endpoint = "https://openai.inference.de-txl.ionos.com/v1/models"
header = {
"Authorization": f"Bearer {IONOS_API_TOKEN}",
"Content-Type": "application/json"
}
requests.get(endpoint, headers=header).json()#!/bin/bash
IONOS_API_TOKEN=[YOUR API TOKEN HERE]
curl -H "Authorization: Bearer ${IONOS_API_TOKEN}" \
--get https://openai.inference.de-txl.ionos.com/v1/models# Python example for text generation
import requests
IONOS_API_TOKEN = "[YOUR API TOKEN HERE]"
MODEL_NAME = "[MODEL NAME HERE]"
PROMPT = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
endpoint = "https://openai.inference.de-txl.ionos.com/v1/chat/completions"
header = {
"Authorization": f"Bearer {IONOS_API_TOKEN}",
"Content-Type": "application/json"
}
body = {
"model": MODEL_NAME,
"messages": PROMPT,
}
requests.post(endpoint, json=body, headers=header).json()#!/bin/bash
IONOS_API_TOKEN=[YOUR API TOKEN HERE]
MODEL_NAME=meta-llama/Meta-Llama-3.1-8B-Instruct
PROMPT='[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]'
BODY="{
\"model\": \"$MODEL_NAME\",
\"messages\": $PROMPT
}"
echo $BODY
curl -H "Authorization: Bearer ${IONOS_API_TOKEN}" \
-H "Content-Type: application/json" \
-d "$BODY" \
https://openai.inference.de-txl.ionos.com/v1/chat/completions