LemonAi.Providers.OpenAICompletions (lemon_ai v0.1.0)

View Source

OpenAI Completions API provider.

This provider implements the OpenAI Chat Completions API format, which is used by many OpenAI-compatible services including:

  • OpenAI (api.openai.com)
  • Groq (api.groq.com)
  • Mistral (api.mistral.ai)
  • xAI/Grok (api.x.ai)
  • Cerebras (api.cerebras.ai)
  • OpenRouter (openrouter.ai)
  • Local servers (llama.cpp, etc.)

SSE Format

The API returns Server-Sent Events (SSE) with data: lines containing JSON chunks:

data: {"id":"chatcmpl-...","choices":[{"delta":{"content":"Hello"}}]}
data: {"id":"chatcmpl-...","choices":[{"delta":{"content":" world"}}]}
data: [DONE]

Compatibility Settings

Different providers have varying support for OpenAI features. The model.compat field can override auto-detection:

  • supports_store - Whether to send store: false
  • supports_developer_role - Use "developer" vs "system" role for reasoning models
  • supports_reasoning_effort - Whether reasoning_effort parameter works
  • max_tokens_field - "max_completion_tokens" (default) or "max_tokens"
  • requires_tool_result_name - Include name in tool results (Mistral)
  • requires_assistant_after_tool_result - Add synthetic assistant message after tool results
  • requires_thinking_as_text - Convert thinking blocks to plain text
  • requires_mistral_tool_ids - Normalize tool IDs to 9 alphanumeric chars