Ollama exposes an OpenAI-compatible HTTP API on port 11434. Because the Cognisafe proxy speaks the same protocol, you can observe all Ollama calls by pointing the proxy’s UPSTREAM_URL at your Ollama instance — no changes to Ollama itself.This is particularly useful in air-gapped environments: all traffic stays on your internal network, and Cognisafe’s safety scoring (if using local scoring) never leaves your infrastructure.
Use patch_openai() — the OpenAI client speaks the same protocol as Ollama’s API:
import cognisafefrom openai import OpenAIcognisafe.configure( api_key="csk_your_key_here", project_id="my-app", proxy_url="http://localhost:8080", # Cognisafe proxy)cognisafe.patch_openai()# No real OpenAI API key needed — Ollama ignores itclient = OpenAI(api_key="ollama")response = client.chat.completions.create( model="llama3.2", # any model you have pulled in Ollama messages=[{"role": "user", "content": "Why is the sky blue?"}],)print(response.choices[0].message.content)
By default, Cognisafe’s safety worker uses gpt-4o-mini (via OPENAI_API_KEY) to score requests. In an air-gapped environment, you have two options:
Disable scoring: if OPENAI_API_KEY is not set, the worker falls back gracefully with score_label: "unscored". Requests are still logged and cost/latency data is captured.
Use a local scoring model: configure an Ollama-backed scoring model by pointing the safety worker at a local OpenAI-compatible endpoint:
# safety_worker env varsOPENAI_API_KEY=ollama # any non-empty valueSCORER_MODEL=llama3.2 # local model name# Override the OpenAI base URL used by the scorer:OPENAI_BASE_URL=http://localhost:11434/v1
Models like llama3.2 or mistral pulled into Ollama work well as scoring models for content_safety and pii_detection. For jailbreak_detection, larger models (70B+) produce more reliable results.
Any model available in the Ollama library works — Cognisafe does not constrain the model field. The proxy passes model through to Ollama unchanged.
# Pull a model before useollama pull llama3.2ollama pull mistralollama pull phi4
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Cognisafe","colors":{"primary":"#22d3ee","light":"#67e8f9","dark":"#0e7490"},"logo":{"light":"https://mintcdn.com/cognisafeltd/PRQ36l5XbfLwcyZ-/logo/logo-light.png?fit=max\u0026auto=format\u0026n=PRQ36l5XbfLwcyZ-\u0026q=85\u0026s=ae1e6f2e9825587a30ed1902b27a1419","dark":"https://mintcdn.com/cognisafeltd/PRQ36l5XbfLwcyZ-/logo/logo-dark.png?fit=max\u0026auto=format\u0026n=PRQ36l5XbfLwcyZ-\u0026q=85\u0026s=47860f0c57bcf24aacfdd95cd2b34bb6"},"favicon":"https://mintlify.s3.us-west-1.amazonaws.com/cognisafeltd/favicon.ico","navbar":{"links":[{"href":"https://status.cognisafe.uk","label":"Status"}],"primary":{"type":"button","label":"Dashboard","href":"https://cognisafe.uk/sign-in"}},"footer":{"socials":{"github":"https://github.com/cognisafe","linkedin":"https://linkedin.com/company/cognisafe"}},"styling":{"latex":false},"navigation":{"global":{"anchors":[{"anchor":"GitHub","icon":"github","href":"https://github.com/cognisafe"},{"anchor":"Support","icon":"envelope","href":"mailto:hello@cognisafe.uk"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"cognisafeltd","hasAudioNarration":false,"actualSubdomain":"cognisafeltd","customDomains":["docs.cognisafe.uk"],"gitSource":{"type":"github","owner":"aigentsmith","repo":"cognisafe-platform","deployBranch":"main","contentDirectory":"docs","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6a499935771a75adafd442f9","collectionId":"99a48da5-fd55-413a-b4b3-c75c9e1a0698","schemaVersion":"v3"},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6a499935771a75adafd442f9:success","clientVersion":"0.0.4005","searchFilterCounts":[{"language":"default","tag":"Docs","count":39},{"language":"default","tag":"Deployment Blueprints","count":8},{"language":"default","tag":"Reference Architectures","count":8},{"language":"default","tag":"Self-hosted Models","count":5},{"language":"default","tag":"API Reference","count":4},{"language":"default","tag":"LLM Providers","count":4},{"language":"default","tag":"Self-hosting","count":4},{"language":"default","tag":"Getting Started","count":3},{"language":"default","tag":"Safety \u0026 Scoring","count":3},{"language":"default","tag":"SDKs","count":3}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-v7-file-tree","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"pause-universal-search-reconcile","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"per-site-search-delta","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-private-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-nav-generations","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-agent-model-picker","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"providers/ollama","slug":"/providers/ollama","pageMetadata":{"title":"Ollama (self-hosted)","description":"Using Cognisafe with Ollama and local models.","href":"/providers/ollama"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Using Cognisafe with Ollama and local models.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,..._provideComponents(),...props.components},{CodeBlock,Heading,Tip}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Tip)_missingMdxReference(`Tip`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`2`,id:`how-it-works`,children:`How it works`}),`\n`,_jsxs(_components.p,{children:[`Ollama exposes an OpenAI-compatible HTTP API on port 11434. Because the Cognisafe proxy speaks the same protocol, you can observe all Ollama calls by pointing the proxy’s `,_jsx(_components.code,{children:`UPSTREAM_URL`}),` at your Ollama instance — no changes to Ollama itself.`]}),`\n`,_jsxs(_components.p,{children:[`This is particularly useful in `,_jsx(_components.strong,{children:`air-gapped environments`}),`: all traffic stays on your internal network, and Cognisafe’s safety scoring (if using local scoring) never leaves your infrastructure.`]}),`\n`,_jsx(Heading,{level:`2`,id:`proxy-configuration`,children:`Proxy configuration`}),`\n`,_jsxs(_components.p,{children:[`Set `,_jsx(_components.code,{children:`UPSTREAM_URL`}),` on the Cognisafe proxy to your Ollama instance:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Proxy service env vars`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`UPSTREAM_URL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`http://localhost:11434`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`If Ollama runs on a different host:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`UPSTREAM_URL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`http://ollama-host.internal:11434`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`sdk-setup`,children:`SDK setup`}),`\n`,_jsxs(_components.p,{children:[`Use `,_jsx(_components.code,{children:`patch_openai()`}),` — the OpenAI client speaks the same protocol as Ollama’s API:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`19`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`19`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` cognisafe`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openai `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` OpenAI`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`cognisafe.configure(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"csk_your_key_here\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` project_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"my-app\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` proxy_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"http://localhost:8080\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Cognisafe proxy`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`cognisafe.patch_openai()`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# No real OpenAI API key needed — Ollama ignores it`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` OpenAI(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ollama\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.chat.completions.create(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"llama3.2\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# any model you have pulled in Ollama`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Why is the sky blue?\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(response.choices[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].message.content)`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`air-gapped-safety-scoring`,children:`Air-gapped safety scoring`}),`\n`,_jsxs(_components.p,{children:[`By default, Cognisafe’s safety worker uses `,_jsx(_components.code,{children:`gpt-4o-mini`}),` (via `,_jsx(_components.code,{children:`OPENAI_API_KEY`}),`) to score requests. In an air-gapped environment, you have two options:`]}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Disable scoring`}),`: if `,_jsx(_components.code,{children:`OPENAI_API_KEY`}),` is not set, the worker falls back gracefully with `,_jsx(_components.code,{children:`score_label: \"unscored\"`}),`. Requests are still logged and cost/latency data is captured.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Use a local scoring model`}),`: configure an Ollama-backed scoring model by pointing the safety worker at a local OpenAI-compatible endpoint:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`5`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# safety_worker env vars`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`OPENAI_API_KEY`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`ollama`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # any non-empty value`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`SCORER_MODEL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`llama3.2`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # local model name`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Override the OpenAI base URL used by the scorer:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`OPENAI_BASE_URL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`http://localhost:11434/v1`})]}),`\n`]})})}),`\n`]}),`\n`]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`Models like `,_jsx(_components.code,{children:`llama3.2`}),` or `,_jsx(_components.code,{children:`mistral`}),` pulled into Ollama work well as scoring models for `,_jsx(_components.code,{children:`content_safety`}),` and `,_jsx(_components.code,{children:`pii_detection`}),`. For `,_jsx(_components.code,{children:`jailbreak_detection`}),`, larger models (70B+) produce more reliable results.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`supported-ollama-models`,children:`Supported Ollama models`}),`\n`,_jsxs(_components.p,{children:[`Any model available in the `,_jsx(_components.a,{href:`https://ollama.com/library`,children:`Ollama library`}),` works — Cognisafe does not constrain the model field. The proxy passes `,_jsx(_components.code,{children:`model`}),` through to Ollama unchanged.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`4`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Pull a model before use`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`ollama`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` pull`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` llama3.2`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`ollama`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` pull`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` mistral`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`ollama`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` pull`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` phi4`})]}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Ollama (self-hosted)","description":"Using Cognisafe with Ollama and local models.","href":"/providers/ollama"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"How it works","slug":"how-it-works","depth":2,"children":[]},{"title":"Proxy configuration","slug":"proxy-configuration","depth":2,"children":[]},{"title":"SDK setup","slug":"sdk-setup","depth":2,"children":[]},{"title":"Air-gapped safety scoring","slug":"air-gapped-safety-scoring","depth":2,"children":[]},{"title":"Supported Ollama models","slug":"supported-ollama-models","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"cognisafeltd","siteName":"Cognisafe","title":"Ollama (self-hosted) - Cognisafe","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-07-04T23:37:38.295Z","originalFileLocation":"providers/ollama.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Using Cognisafe with Ollama and local models.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Cognisafe\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/x-icon\" sizes=\"180x180\" href=\"https://mintlify.s3.us-west-1.amazonaws.com/cognisafeltd/favicon.ico\">\u003clink data-mint-head rel=\"icon\" type=\"image/x-icon\" sizes=\"32x32\" href=\"https://mintlify.s3.us-west-1.amazonaws.com/cognisafeltd/favicon.ico\">\u003clink data-mint-head rel=\"icon\" type=\"image/x-icon\" sizes=\"16x16\" href=\"https://mintlify.s3.us-west-1.amazonaws.com/cognisafeltd/favicon.ico\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"https://mintlify.s3.us-west-1.amazonaws.com/cognisafeltd/favicon.ico\">\u003cmeta data-mint-head property=\"og:title\" content=\"Ollama (self-hosted) - Cognisafe\">\u003cmeta data-mint-head property=\"og:description\" content=\"Using Cognisafe with Ollama and local models.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Cognisafe\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.cognisafe.uk/providers/ollama\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://cognisafeltd.mintlify.app/_mintlify/api/og/v2?division=Self-hosted+Models\u0026amp;title=Ollama+%28self-hosted%29\u0026amp;description=Using+Cognisafe+with+Ollama+and+local+models.\u0026amp;theme=11d19a25bed4fa343dc13611\u0026amp;signature=18634e8ff431a398edbefcaa4c69f3c7ae12473d0e2a1f393c8bd8edb438673b\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Ollama (self-hosted) - Cognisafe\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Using Cognisafe with Ollama and local models.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://cognisafeltd.mintlify.app/_mintlify/api/og/v2?division=Self-hosted+Models\u0026amp;title=Ollama+%28self-hosted%29\u0026amp;description=Using+Cognisafe+with+Ollama+and+local+models.\u0026amp;theme=11d19a25bed4fa343dc13611\u0026amp;signature=18634e8ff431a398edbefcaa4c69f3c7ae12473d0e2a1f393c8bd8edb438673b\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"https://mintlify.s3.us-west-1.amazonaws.com/cognisafeltd/_generated/favicon/browserconfig.xml?v=3\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Cognisafe\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#22d3ee\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.cognisafe.uk/providers/ollama\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/providers/ollama.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.cognisafe.uk/#organization\",\"name\":\"Cognisafe\",\"url\":\"https://docs.cognisafe.uk\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/cognisafeltd/PRQ36l5XbfLwcyZ-/logo/logo-light.png?fit=max\u0026auto=format\u0026n=PRQ36l5XbfLwcyZ-\u0026q=85\u0026s=ae1e6f2e9825587a30ed1902b27a1419\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.cognisafe.uk#website\",\"name\":\"Cognisafe\",\"url\":\"https://docs.cognisafe.uk\",\"publisher\":{\"@id\":\"https://docs.cognisafe.uk/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.cognisafe.uk/providers/ollama#webpage\",\"url\":\"https://docs.cognisafe.uk/providers/ollama\",\"name\":\"Ollama (self-hosted)\",\"description\":\"Using Cognisafe with Ollama and local models.\",\"dateModified\":\"2026-07-04T23:37:38.295Z\",\"isPartOf\":{\"@id\":\"https://docs.cognisafe.uk#website\"},\"breadcrumb\":{\"@id\":\"https://docs.cognisafe.uk/providers/ollama#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.cognisafe.uk/providers/ollama#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Cognisafe\",\"item\":\"https://docs.cognisafe.uk\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ollama (self-hosted)\",\"item\":\"https://docs.cognisafe.uk/providers/ollama\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.cognisafe.uk/providers/ollama#article\",\"headline\":\"Ollama (self-hosted)\",\"name\":\"Ollama (self-hosted)\",\"description\":\"Using Cognisafe with Ollama and local models.\",\"url\":\"https://docs.cognisafe.uk/providers/ollama\",\"mainEntityOfPage\":{\"@id\":\"https://docs.cognisafe.uk/providers/ollama#webpage\"},\"dateModified\":\"2026-07-04T23:37:38.295Z\",\"publisher\":{\"@id\":\"https://docs.cognisafe.uk/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.cognisafe.uk#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Cognisafe\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Cognisafe","nav":{"global":{"anchors":[{"anchor":"GitHub","icon":"github","href":"https://github.com/cognisafe"},{"anchor":"Support","icon":"envelope","href":"mailto:hello@cognisafe.uk"}]},"tabs":[{"tab":"Docs","groups":[{"group":"Getting Started","pages":[{"title":"Introduction","href":"/introduction"},{"title":"Quickstart","href":"/quickstart"},{"title":"How it works","href":"/how-it-works"}]},{"group":"SDKs","pages":[{"title":"Python SDK","href":"/sdk/python"},{"title":"Node.js / TypeScript SDK","href":"/sdk/nodejs"},{"title":"Java SDK","href":"/sdk/java"}]},{"group":"LLM Providers","pages":[{"title":"OpenAI","href":"/providers/openai"},{"title":"Anthropic","href":"/providers/anthropic"},{"title":"Mistral","href":"/providers/mistral"},{"title":"Azure OpenAI","description":"Using Cognisafe with Azure OpenAI.","href":"/providers/azure-openai"}]},{"group":"Self-hosted Models","pages":[{"title":"Ollama (self-hosted)","href":"/providers/ollama"},{"title":"Hugging Face (TGI \u0026 Inference Endpoints)","description":"Route Hugging Face Text Generation Inference and Inference Endpoints traffic through Cognisafe.","href":"/providers/huggingface"},{"title":"NVIDIA NIM","href":"/providers/nvidia-nim"},{"title":"vLLM","href":"/providers/vllm"},{"title":"LM Studio","href":"/providers/lm-studio"}]},{"group":"Self-hosting","pages":[{"title":"Self-hosting overview","href":"/self-hosting/overview"},{"title":"Docker Compose","href":"/self-hosting/docker-compose"},{"title":"Kubernetes / Railway","href":"/self-hosting/kubernetes"},{"title":"Environment variables","href":"/self-hosting/environment-variables"}]},{"group":"Integrations","pages":[{"title":"Telemetry ingest — Observra \u0026 OpenTelemetry","href":"/integrations/telemetry-ingest"}]},{"group":"Reference Architectures","pages":[{"title":"Azure OpenAI + APIM + Cognisafe","href":"/reference-architectures/azure-openai-apim"},{"title":"Semantic Kernel Agent Runtime","href":"/reference-architectures/semantic-kernel"},{"title":"MCP Tool Governance","href":"/reference-architectures/mcp-tool-governance"},{"title":"AKS Production Reference Architecture","href":"/reference-architectures/aks-production"},{"title":"Air-gapped Enterprise Deployment","href":"/reference-architectures/air-gapped"},{"title":"SIEM Integration Reference Architecture","href":"/reference-architectures/siem-integration"},{"title":"SOC Integration","href":"/reference-architectures/soc-integration"},{"title":"Human-in-the-Loop Approval Workflows","href":"/reference-architectures/hitl-approval"}]},{"group":"Deployment Blueprints","pages":[{"title":"AKS Deployment","href":"/blueprints/aks"},{"title":"Kubernetes Helm Install","href":"/blueprints/kubernetes-helm"},{"title":"Azure API Management Integration","href":"/blueprints/apim"},{"title":"Azure OpenAI Insertion","href":"/blueprints/azure-openai"},{"title":"Private Endpoint Architecture","href":"/blueprints/private-endpoint"},{"title":"SIEM Forwarding","href":"/blueprints/siem-forwarding"},{"title":"Azure Sentinel Integration","href":"/blueprints/azure-sentinel"},{"title":"Grafana \u0026 Prometheus Monitoring","href":"/blueprints/grafana-prometheus"}]},{"group":"Safety \u0026 Scoring","pages":[{"title":"OWASP LLM Top 10 coverage","href":"/safety/owasp-coverage"},{"title":"Custom scorers","href":"/safety/custom-scorers"},{"title":"Severity scale","href":"/safety/severity-scale"}]}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/api-reference/overview"}]}]},"title":"Ollama (self-hosted) - Cognisafe","buildId":"dpl_48qhjNLiu9iJQQSZJz9Fa2ihBbPH","deploymentId":"dpl_48qhjNLiu9iJQQSZJz9Fa2ihBbPH","dynamics":[],"chunks":[]}