Create chat completions with any available AI model
curl --request POST \
--url https://modelswitch.io/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": {},
"n": 123
}
'{
"id": "<string>",
"object": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}Authorization: Bearer ms-YOUR_KEY
GET /v1/models to retrieve available IDs (e.g., gpt-4o, claude-sonnet-4).role — "system", "user", or "assistant"content — message text as a stringtop_p.true, the response is delivered as a series of server-sent events (SSE). Each chunk contains a partial delta. The stream ends with data: [DONE].top_p probability mass. Do not use alongside temperature.n.curl https://modelswitch.io/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ms-YOUR_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is ModelSwitch?"}
],
"temperature": 0.7,
"max_tokens": 500,
"stream": false
}'
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1709000000,
"model": "gpt-4o",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "ModelSwitch is a unified AI API gateway..."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}
"chat.completion" for non-streaming responses.n is set.stream: true, the API returns newline-delimited SSE events. Each event is a JSON object with a delta instead of a message:
{
"id": "chatcmpl-abc123",
"object": "chat.completion.chunk",
"choices": [{
"delta": {"content": "Model"},
"index": 0,
"finish_reason": null
}]
}
choices[0].delta.content from each chunk. The stream ends with:
data: [DONE]
stream=True / stream: true. The SDK iterates over chunks and exposes .choices[0].delta.content on each.curl --request POST \
--url https://modelswitch.io/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": {},
"n": 123
}
'{
"id": "<string>",
"object": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}