OpenAI Compatibility Guide
Seamlessly integrate Ask Sage using the standard OpenAI API format
Table of contents
What’s New?
Ask Sage now supports the OpenAI message format, making it incredibly easy to:
Switch from OpenAI to Ask Sage with minimal code changes
Use the same API format and patterns as OpenAI
Leverage the standard OpenAI API format you already know
OpenAI-Compatible Endpoints
Chat Completions
The main endpoint for conversational AI using the standard OpenAI format.
Authorization header Request Parameters
Bearer token authentication: Bearer YOUR_API_KEY
The AI model to use (e.g., "gpt-4o-mini", "claude-35-sonnet", etc.)
Array of message objects with roles: system, user, or assistant
- role: Message role (system, user, assistant)
- content: Message content text
Controls randomness (0.0-2.0). Higher values make output more creative. Default: 1.0
Maximum number of tokens to generate in the response
Nucleus sampling parameter (0.0-1.0). Default: 1.0
Reduces likelihood of repeating tokens (-2.0 to 2.0). Default: 0.0
Increases likelihood of new topics (-2.0 to 2.0). Default: 0.0
Array of tool/function definitions for function calling
Controls tool usage: "none", "auto", or specific tool. Default: "auto"
Response Details
Response Structure:
- id: Unique completion ID
- object: "chat.completion"
- created: Unix timestamp
- model: Model used
- choices: Array containing:
- index: Choice index
- message: Response message object with role and content
- finish_reason: Reason for completion (stop, length, etc.)
- usage: Token usage statistics
Invalid request format or missing required parameters
Authentication failure - invalid or missing API key
Example: Basic Chat Completion
curl -X POST 'https://api.asksage.ai/server/openai/v1/chat/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Ask Sage?"}
]
}'Example: Multi-Turn Conversation
curl -X POST 'https://api.asksage.ai/server/openai/v1/chat/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "My name is Alice."},
{"role": "assistant", "content": "Nice to meet you, Alice!"},
{"role": "user", "content": "What'\''s my name?"}
],
"temperature": 0.3
}'Example: Function Calling
curl -X POST 'https://api.asksage.ai/server/openai/v1/chat/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "What'\''s the weather like in San Francisco?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}'List Available Models
Retrieve a list of all available AI models in OpenAI format.
Request Parameters
Bearer token authentication: Bearer YOUR_API_KEY
Response Details
response (object) - Contains:
- object: "list"
- data: Array of model objects with:
- id: Model identifier
- object: "model"
- created: Creation timestamp
- owned_by: Model provider
Authentication failure
curl -X GET 'https://api.asksage.ai/server/openai/v1/models' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Accept: application/json'How It Works
Ask Sage's openai/v1/* endpoints follow the exact same API specification as OpenAI, making integration seamless.
Using the Same Pattern as OpenAI
You can use Ask Sage's API with the same request/response patterns you're familiar with from OpenAI. Simply point your requests to Ask Sage's base URL with Bearer token authentication.
https://api.openai.com/v1), use Ask Sage's base URL (https://api.asksage.ai/server/openai/v1) Example: Making Requests
# Ask Sage API (OpenAI-compatible format)
curl -X POST 'https://api.asksage.ai/server/openai/v1/chat/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'Migration Guide
Key Benefits
Minimal code changes to switch from OpenAI to Ask Sage
Use the same API patterns and structure as OpenAI