gpt-4
Model Overview
The model represents a significant leap forward in conversational AI technology. It offers enhanced understanding and generation of natural language, capable of handling complex and nuanced dialogues with greater coherence and context sensitivity. This model is designed to mimic human-like conversation more closely than ever before.
How to Make a Call
API Schema
Creates a chat completion using a language model, allowing interactive conversation by predicting the next response based on the given chat history. This is useful for AI-driven dialogue systems and virtual assistants.
An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
512
The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API.
512
If set to True, the model response data will be streamed to the client as it is generated using server-sent events.
false
Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools. Specifying a particular tool via {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool. none is the default when no tools are present. auto is the default if tools are present.
none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools.
Whether to enable parallel function calling during tool use.
How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
Whether to return log probabilities of the output tokens or not. If True, returns the log probabilities of each output token returned in the content of message.
An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to True if this parameter is used.
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result.
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
POST /v1/chat/completions HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 529
{
"model": "gpt-4",
"messages": [
{
"role": "user",
"content": "text",
"name": "text"
}
],
"max_completion_tokens": 512,
"max_tokens": 512,
"stream": false,
"stream_options": {
"include_usage": true
},
"tools": [
{
"type": "function",
"function": {
"description": "text",
"name": "text",
"parameters": null,
"strict": true,
"required": [
"text"
]
}
}
],
"tool_choice": "none",
"parallel_tool_calls": true,
"n": 1,
"stop": "text",
"logprobs": true,
"top_logprobs": 1,
"logit_bias": {
"ANY_ADDITIONAL_PROPERTY": 1
},
"frequency_penalty": 1,
"presence_penalty": 1,
"seed": 1,
"temperature": 1,
"top_p": 1
}
No content
Responses Endpoint
This endpoint is currently used only with OpenAI models. Some models support both the /chat/completions
and /responses
endpoints, while others support only one of them. OpenAI has announced plans to expand the capabilities of the /responses
endpoint in the future.
Model ID used to generate the response.
Text, image, or file inputs to the model, used to generate a response.
A text input to the model, equivalent to a text input with the user role.
A system (or developer) message inserted into the model's context.
When using along with previous_response_id, the instructions from a previous response will not be carried over to the next response. This makes it simple to swap out system (or developer) messages in new responses.
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.
512
Whether to allow the model to run tool calls in parallel.
The unique ID of the previous response to the model. Use this to create multi-turn conversations.
Whether to store the generated model response for later retrieval via API.
false
If set to true, the model response data will be streamed to the client as it is generated using server-sent events.
false
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.
How the model should select which tool (or tools) to use when generating a response.
Controls which (if any) tool is called by the model.
none means the model will not call any tool and instead generates a message.
auto means the model can pick between generating a message or calling one or more tools.
required means the model must call one or more tools.
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
The truncation strategy to use for the model response.
- auto: If the context of this response and previous ones exceeds the model's context window size, the model will truncate the response to fit the context window by dropping input items in the middle of the conversation.
- disabled (default): If a model response will exceed the context window size for a model, the request will fail with a 400 error.
disabled
Possible values: POST /v1/responses HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 672
{
"model": "openai/gpt-4o",
"input": "text",
"include": [
"message.input_image.image_url"
],
"instructions": "text",
"max_output_tokens": 512,
"metadata": {
"ANY_ADDITIONAL_PROPERTY": "text"
},
"parallel_tool_calls": true,
"previous_response_id": "text",
"prompt": {
"id": "text",
"variables": {
"ANY_ADDITIONAL_PROPERTY": "text"
},
"version": "text"
},
"reasoning": {
"effort": "low",
"summary": "auto"
},
"store": false,
"stream": false,
"temperature": 1,
"text": {
"format": {
"type": "text"
}
},
"tool_choice": "none",
"tools": [
{
"type": "web_search_preview",
"search_context_size": "low",
"user_location": {
"type": "approximate",
"city": "text",
"country": "text",
"region": "text",
"timezone": "text"
}
}
],
"top_p": 1,
"truncation": "disabled"
}
No content
Code Example
import requests
response = requests.post(
"https://api.aimlapi.com/v1/chat/completions",
headers={
"Content-Type":"application/json",
# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
"Authorization":"Bearer <YOUR_AIMLAPI_KEY>",
"Content-Type":"application/json"
},
json={
"model":"gpt-4",
"messages":[
{
"role":"user",
# Insert your question for the model here, instead of Hello:
"content":"Hello"
}
]
}
)
data = response.json()
print(data)
Last updated
Was this helpful?