OpenAI Integration

Create chat completion (OpenAI format)

Creates a chat completion using OpenAI-compatible format. Supports streaming via SSE.

Async inference: Send x-bf-async: true to submit the request as a background job and receive a job ID immediately. Poll with x-bf-async-id: <job-id> to retrieve the result. When the job is still processing, the response will have an empty choices array. When completed, choices will contain the full result. See Async Inference for details.

Note: This endpoint also works without the /v1 prefix (e.g., /openai/chat/completions).

POST
/openai/v1/chat/completions
AuthorizationBearer <token>

Bearer token authentication. Use your MPilot virtual-key JWT or admin JWT. Virtual keys (prefixed with sk-bf-) can also be passed here.

In: header

Header Parameters

x-bf-async?string

Set to true to submit this request as an async job. Returns immediately with a job ID. Not compatible with streaming.

Value in"true"
x-bf-async-id?string

Poll for results of a previously submitted async job by providing the job ID returned from the initial async request.

x-bf-async-job-result-ttl?integer

Override the default result TTL in seconds. Results expire after this duration from completion time.

Default3600
modelstring

Model identifier (e.g., gpt-4, gpt-3.5-turbo)

messagesarray<OpenAIMessage>

List of messages in the conversation

stream?boolean

Whether to stream the response

max_tokens?integer

Maximum tokens to generate (legacy, use max_completion_tokens)

max_completion_tokens?integer

Maximum tokens to generate

temperature?number
Range0 <= value <= 2
top_p?number
frequency_penalty?number
Range-2 <= value <= 2
presence_penalty?number
Range-2 <= value <= 2
logit_bias?object

Empty Object

logprobs?boolean
top_logprobs?integer
n?integer
stop?string | array<string>
seed?integer
user?string
tools?array<object>
tool_choice?string | object
parallel_tool_calls?boolean
response_format?object

Format for the response

Empty Object

reasoning_effort?string

OpenAI reasoning effort level

Value in"none" | "minimal" | "low" | "medium" | "high" | "xhigh"
service_tier?string
stream_options?object
fallbacks?array<string>

Fallback models

Response Body

curl -X POST "https://loading/{AI_GATEWAY_URL}/openai/v1/chat/completions" \  -H "x-bf-async: true" \  -H "x-bf-async-id: string" \  -H "x-bf-async-job-result-ttl: 3600" \  -H "Content-Type: application/json" \  -d '{    "model": "gpt-4",    "messages": [      {        "role": "system"      }    ]  }'
{
  "id": "string",
  "choices": [
    {
      "index": 0,
      "finish_reason": "string",
      "log_probs": {
        "content": [
          {
            "bytes": [
              0
            ],
            "logprob": 0,
            "token": "string",
            "top_logprobs": [
              {
                "bytes": [
                  0
                ],
                "logprob": 0,
                "token": "string"
              }
            ]
          }
        ],
        "refusal": [
          {
            "bytes": [
              0
            ],
            "logprob": 0,
            "token": "string"
          }
        ],
        "text_offset": [
          0
        ],
        "token_logprobs": [
          0
        ],
        "tokens": [
          "string"
        ],
        "top_logprobs": [
          {
            "property1": 0,
            "property2": 0
          }
        ]
      },
      "text": "string",
      "message": {
        "role": "assistant",
        "name": "string",
        "content": "string",
        "tool_call_id": "string",
        "refusal": "string",
        "audio": {
          "id": "string",
          "data": "string",
          "expires_at": 0,
          "transcript": "string"
        },
        "reasoning": "string",
        "reasoning_details": [
          {
            "id": "string",
            "index": 0,
            "type": "reasoning.summary",
            "summary": "string",
            "text": "string",
            "signature": "string",
            "data": "string"
          }
        ],
        "annotations": [
          {
            "type": "string",
            "url_citation": {
              "start_index": 0,
              "end_index": 0,
              "title": "string",
              "url": "string",
              "sources": {},
              "type": "string"
            }
          }
        ],
        "tool_calls": [
          {
            "index": 0,
            "type": "string",
            "id": "string",
            "function": {
              "name": "string",
              "arguments": "string"
            }
          }
        ]
      },
      "delta": {
        "role": "string",
        "content": "string",
        "refusal": "string",
        "audio": {
          "id": "string",
          "data": "string",
          "expires_at": 0,
          "transcript": "string"
        },
        "reasoning": "string",
        "reasoning_details": [
          {
            "id": "string",
            "index": 0,
            "type": "reasoning.summary",
            "summary": "string",
            "text": "string",
            "signature": "string",
            "data": "string"
          }
        ],
        "tool_calls": [
          {
            "index": 0,
            "type": "string",
            "id": "string",
            "function": {
              "name": "string",
              "arguments": "string"
            }
          }
        ]
      }
    }
  ],
  "created": 0,
  "model": "string",
  "object": "string",
  "service_tier": "string",
  "system_fingerprint": "string",
  "usage": {
    "prompt_tokens": 0,
    "prompt_tokens_details": {
      "text_tokens": 0,
      "audio_tokens": 0,
      "image_tokens": 0,
      "cached_read_tokens": 0,
      "cached_write_tokens": 0
    },
    "completion_tokens": 0,
    "completion_tokens_details": {
      "text_tokens": 0,
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "citation_tokens": 0,
      "num_search_queries": 0,
      "reasoning_tokens": 0,
      "image_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "total_tokens": 0,
    "cost": {
      "input_tokens_cost": 0,
      "output_tokens_cost": 0,
      "reasoning_tokens_cost": 0,
      "citation_tokens_cost": 0,
      "search_queries_cost": 0,
      "request_cost": 0,
      "total_cost": 0
    }
  },
  "extra_fields": {
    "request_type": "string",
    "provider": "openai",
    "model_requested": "string",
    "model_deployment": "string",
    "latency": 0,
    "chunk_index": 0,
    "raw_request": {},
    "raw_response": {},
    "cache_debug": {
      "cache_hit": true,
      "cache_id": "string",
      "hit_type": "string",
      "requested_provider": "string",
      "requested_model": "string",
      "provider_used": "string",
      "model_used": "string",
      "input_tokens": 0,
      "threshold": 0,
      "similarity": 0
    }
  },
  "search_results": [
    {
      "title": "string",
      "url": "string",
      "date": "string",
      "last_updated": "string",
      "snippet": "string",
      "source": "string"
    }
  ],
  "videos": [
    {
      "url": "string",
      "thumbnail_url": "string",
      "thumbnail_width": 0,
      "thumbnail_height": 0,
      "duration": 0
    }
  ],
  "citations": [
    "string"
  ]
}
{
  "event_id": "string",
  "type": "string",
  "is_bifrost_error": true,
  "status_code": 0,
  "error": {
    "type": "string",
    "code": "string",
    "message": "string",
    "param": "string",
    "event_id": "string"
  },
  "extra_fields": {
    "provider": "openai",
    "model_requested": "string",
    "request_type": "string"
  }
}
{
  "event_id": "string",
  "type": "string",
  "is_bifrost_error": true,
  "status_code": 0,
  "error": {
    "type": "string",
    "code": "string",
    "message": "string",
    "param": "string",
    "event_id": "string"
  },
  "extra_fields": {
    "provider": "openai",
    "model_requested": "string",
    "request_type": "string"
  }
}
On this page

On this page

No Headings