Chat Completions API (OpenAI-compatible)
ScriptRun exposes an OpenAI-compatible chat completions endpoint. It accepts a
standard OpenAI chat-completion request body, proxies it to the requested model, and
returns the provider's response unchanged. This lets you reuse existing OpenAI
client libraries by simply pointing their base_url at ScriptRun.
Endpoint
POST https://scriptrun.ai/v1/chat/completions
Unlike the rest of the API, this endpoint lives at /v1/... (not /api/v1/...) so
that it lines up with the path OpenAI SDKs append to base_url automatically.
Authentication
This endpoint authenticates with a Bearer token (the OpenAI convention), not the
X-Api-Key header used elsewhere. Pass your ScriptRun API key as the bearer token:
Authorization: Bearer <Your API Key>
Request Body
The body is a standard OpenAI chat-completion payload. At minimum, provide model and
messages:
| Name | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model identifier to run the request against (e.g. gpt-4o). |
messages | array | Yes | List of chat messages, each with a role and content. |
| ... | No | Any other OpenAI chat-completion parameter is passed through as-is. |
Response
On success the endpoint returns the provider's chat-completion response body verbatim, in OpenAI format. Errors are returned in OpenAI's error shape:
{
"error": {
"message": "Invalid model_name",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Examples
Using the OpenAI SDK
from openai import OpenAI
client = OpenAI(
api_key="<Your API Key>",
base_url="https://scriptrun.ai/v1",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
)
print(response.choices[0].message.content)
Using requests
import requests
url = "https://scriptrun.ai/v1/chat/completions"
headers = {
"Authorization": "Bearer <Your API Key>",
"Content-Type": "application/json",
}
data = {
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
Using curl
curl -X POST "https://scriptrun.ai/v1/chat/completions" \
-H "Authorization: Bearer <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'
Example success response:
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 9,
"total_tokens": 29
}
}
Responses
- 200: Chat completion result in OpenAI format (proxied from the provider).
- 400: Invalid request — for example a missing
modelfield. - 500: Execution or upstream provider error.
The HTTP status code mirrors the upstream provider response, so codes beyond those
listed above (such as 401 or 429) may be passed straight through from the provider.
The request is executed synchronously and waits for the provider to respond (up to a
60-second server-side timeout). For long-running, multi-node automations use the
Workflow API run / workflow_result endpoints instead.