Principle:Ollama Ollama OpenAI Request Translation
| Knowledge Sources | |
|---|---|
| Domains | API_Design, Data_Transformation |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
A request format translation mechanism that converts OpenAI ChatCompletion and Completion requests into Ollama's native request format, handling field mapping, type conversion, and image URL decoding.
Description
OpenAI Request Translation converts incoming requests in OpenAI's API format to Ollama's internal format. This involves mapping field names (max_tokens → num_predict, frequency_penalty → frequency_penalty), translating message formats (including multimodal content with image URLs), converting tool definitions, and normalizing streaming options.
The translation handles OpenAI-specific features like image URLs in message content (data URIs and HTTP URLs), structured tool/function calling formats, and response format specifications.
Usage
Use this principle when implementing API compatibility layers that must translate between different request schemas. The translation should be lossless for supported features and gracefully degrade for unsupported ones.
Theoretical Basis
Request translation maps:
| OpenAI Field | Ollama Field | Notes |
|---|---|---|
| model | Model | Direct mapping |
| messages | Messages | Content type conversion (string vs array) |
| messages[].content (image_url) | Messages[].Images | Base64 decode from data URI or fetch HTTP URL |
| tools | Tools | Direct mapping |
| temperature | Options.Temperature | Direct mapping |
| top_p | Options.TopP | Direct mapping |
| max_tokens / max_completion_tokens | Options.NumPredict | Rename |
| frequency_penalty | Options.FrequencyPenalty | Direct mapping |
| presence_penalty | Options.PresencePenalty | Direct mapping |
| seed | Options.Seed | Direct mapping |
| stop | Options.Stop | Direct mapping |
| stream | Stream | Direct mapping |