Skip to main content
POST
https://api.savegate.ai
/
v1
/
chat
/
completions
Chat Completions
curl --request POST \
  --url https://api.savegate.ai/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {}
  ],
  "temperature": 123,
  "max_tokens": 123,
  "stream": true,
  "top_p": 123,
  "frequency_penalty": 123,
  "presence_penalty": 123,
  "stop": {},
  "functions": [
    {}
  ],
  "function_call": {}
}
'
{
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "<string>",
        "content": "<string>",
        "function_call": {}
      },
      "finish_reason": "<string>"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}

Request

Create a chat completion using any supported model.

Headers

HeaderValueRequired
AuthorizationBearer YOUR_API_KEYYes
Content-Typeapplication/jsonYes

Body Parameters

model
string
required
The model to use (e.g., gpt-4, claude-3-5-sonnet-20241022, gemini-1.5-pro)
messages
array
required
Array of message objects with role and content
temperature
number
default:"1"
Sampling temperature between 0 and 2
max_tokens
integer
Maximum number of tokens to generate
stream
boolean
default:"false"
Whether to stream responses
top_p
number
default:"1"
Nucleus sampling parameter
frequency_penalty
number
default:"0"
Penalize frequent tokens (-2.0 to 2.0)
presence_penalty
number
default:"0"
Penalize new tokens (-2.0 to 2.0)
stop
string or array
Stop sequences
functions
array
Function definitions for function calling
function_call
string or object
Controls function calling behavior

Response

Response Fields

id
string
Unique completion ID
object
string
Object type (always chat.completion)
created
integer
Unix timestamp
model
string
Model used for completion
choices
array
Array of completion choices
usage
object
Token usage information

Examples

curl https://api.savegate.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-savegate-xxxxxxxxxxxxx" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "What is the capital of France?"
      }
    ],
    "temperature": 0.7
  }'

Response Example

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "The capital of France is Paris."
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 8,
    "total_tokens": 28
  }
}

Streaming Example

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in response:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Function Calling Example

functions = [
    {
        "name": "get_weather",
        "description": "Get current weather",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "City and state, e.g. San Francisco, CA"
                },
                "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
            },
            "required": ["location"]
        }
    }
]

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "What's the weather in Boston?"}],
    functions=functions,
    function_call="auto"
)

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