{"id":48499695,"url":"https://github.com/ahrefs/ocaml-ai-sdk","last_synced_at":"2026-04-25T17:00:31.299Z","repository":{"id":349589479,"uuid":"1202929702","full_name":"ahrefs/ocaml-ai-sdk","owner":"ahrefs","description":"OCaml port of Vercel's AI SDK. Melange bindings included.","archived":false,"fork":false,"pushed_at":"2026-04-14T15:46:06.000Z","size":1058,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-14T17:26:40.442Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahrefs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-06T14:47:56.000Z","updated_at":"2026-04-14T15:45:19.000Z","dependencies_parsed_at":"2026-04-25T17:00:25.968Z","dependency_job_id":null,"html_url":"https://github.com/ahrefs/ocaml-ai-sdk","commit_stats":null,"previous_names":["ahrefs/ocaml-ai-sdk"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ahrefs/ocaml-ai-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Focaml-ai-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Focaml-ai-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Focaml-ai-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Focaml-ai-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahrefs","download_url":"https://codeload.github.com/ahrefs/ocaml-ai-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Focaml-ai-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32269463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T09:15:33.318Z","status":"ssl_error","status_checked_at":"2026-04-25T09:15:31.997Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-07T14:02:51.574Z","updated_at":"2026-04-25T17:00:31.290Z","avatar_url":"https://github.com/ahrefs.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ocaml-ai-sdk\n\nType-safe, provider-agnostic AI model abstraction for OCaml, inspired by the [Vercel AI SDK](https://sdk.vercel.ai). Targets wire compatibility with AI SDK v6 so you can pair an OCaml backend with `@ai-sdk/react` frontends.\n\n## Libraries\n\n| Library | opam lib | Description |\n|---------|----------|-------------|\n| `ai_provider` | `ocaml-ai-sdk.ai_provider` | Provider abstraction — language model module types, tool definitions, prompt types, GADT-based provider options |\n| `ai_provider_anthropic` | `ocaml-ai-sdk.ai_provider_anthropic` | Anthropic Messages API — streaming SSE, thinking, cache control, full Claude model catalog |\n| `ai_provider_openai` | `ocaml-ai-sdk.ai_provider_openai` | OpenAI Chat Completions API — streaming SSE, tool calling with strict mode, GPT-4o/o1/o3/o4-mini catalog |\n| `ai_core` | `ocaml-ai-sdk.ai_core` | Core SDK — `generate_text`, `stream_text` (with tool loops), UIMessage stream protocol, server handler, structured output |\n| `ai_sdk_react` | `ai-sdk-react.ai_sdk_react` | Melange bindings for `@ai-sdk/react` — `useChat`, `useCompletion`, v6 part types |\n\n## Quick start\n\n```\nopam install ocaml-ai-sdk\n```\n\n### One-shot generation\n\n```ocaml\nopen Ai_core\nopen Ai_provider_anthropic\n\nlet () =\n  Lwt_main.run @@\n  let model = Anthropic.create_model \"claude-sonnet-4-20250514\" in\n  let%lwt result = Generate_text.generate ~model ~prompt:\"Say hello\" () in\n  Lwt_io.printl result.text\n```\n\n### Streaming\n\n```ocaml\nlet () =\n  Lwt_main.run @@\n  let model = Anthropic.create_model \"claude-sonnet-4-20250514\" in\n  let%lwt result = Stream_text.stream ~model ~prompt:\"Tell me a joke\" () in\n  Lwt_stream.iter_s Lwt_io.printl result.text_stream\n```\n\n### Chat server (with UIMessage protocol)\n\n```ocaml\nlet handler = Server_handler.create ~model ()\n(* Serves SSE responses compatible with useChat() from @ai-sdk/react *)\n```\n\nSee [`examples/`](examples/) for complete runnable demos including tool use, thinking, structured output, and full-stack Melange apps.\n\n## Architecture\n\n```\nai_provider          Provider abstraction (module types, GADT options)\n├── ai_provider_anthropic   Anthropic implementation\n├── ai_provider_openai      OpenAI implementation\n└── ai_core                 Core SDK (generate, stream, UIMessage protocol)\n```\n\n**Key design choices:**\n\n- **Provider options** use an extensible GADT (`type _ key = ..`) for compile-time type-safe provider-specific settings (e.g. thinking budget, cache control)\n- **Prompt types** are role-constrained variants — `System` accepts only strings, `User` accepts text + files, etc.\n- **Streaming** uses `Lwt_stream.t` — `stream_text` returns synchronously with streams populated by a background Lwt task\n- **UIMessage protocol** emits SSE chunks matching the `ai@6` Zod schemas exactly, so `useChat()` works without adaptation\n\n## AI SDK v6 compatibility\n\nThe UIMessage stream protocol (`x-vercel-ai-ui-message-stream: v1`) is wire-compatible with:\n\n- `@ai-sdk/react` 3.x (`useChat`, `useCompletion`)\n- `ai` 6.x (core SDK)\n\nAll chunk types are supported: text, reasoning, tool call (start/delta/result), source, file, data, error, finish message/step.\n\n## Requirements\n\n- OCaml \u003e= 4.14\n- For Melange bindings: `melange` \u003e= 4.0.0\n\n## Development\n\n```sh\nmake build    # Build all libraries\nmake test     # Run test suites\nmake dev      # Watch mode\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrefs%2Focaml-ai-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahrefs%2Focaml-ai-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrefs%2Focaml-ai-sdk/lists"}