Menu ▾ ▴

#3 Add `openai` provider to `orko-providers` crate

closed
nobody
2026-11-21
2026-08-11
Anonymous
No

Originally created by: SAMAD101

Summary

This is the foundation issue for orko-providers: the OpenAI-compatible engine plus the openai preset. Every OpenAI-compatible provider (#4 google, [#5] deepseek, and later groq/together/openrouter/ollama/moonshot/qwen/vllm/llamacpp) is a thin preset over this engine, so the design here matters most.

Architecture (decision of record — see the // TODO block in crates/orko-providers/src/lib.rs)

Codec / transport split:

  • Codec — pure computation, no IO, no runtime:
  • build the Chat Completions request JSON from orko_core::CompletionRequest
  • parse the SSE stream into orko_core::CompletionChunk (eventsource-stream for framing)
  • translate orko_core::Content parts to the OpenAI wire shape: text-only messages stay plain strings (wire shape preserved); multi-part content becomes the array form with nested image_url; base64 media renders as data: URLs
  • Transport — one small object-safe trait, std vocabulary only: POST bytes + headers → streaming byte response.
  • Default impl: hyper 1.x + hyper-util + hyper-rustls behind a transport-tokio feature (default on). Connection driven with select!, no spawn.
  • Users with exotic needs (proxies, custom TLS, own pooling) inject their own transport; the codec never changes.
  • The deeper escape hatch remains orko_core::Provider itself — implement it with any HTTP client and the rest of orko works untouched. Document both hatches in the crate README.

Wire details

  • Base URL https://api.openai.com/v1 (configurable), endpoint POST /chat/completions
  • Auth: Authorization: Bearer $OPENAI_API_KEY (conventional env key)
  • Streaming: "stream": true, SSE data: lines terminated by data: [DONE]; request usage via "stream_options": {"include_usage": true}
  • Tool calls arrive as index-grouped fragments — maps directly onto orko_core::ToolCallDelta (group by index, concatenate arguments)
  • Map finish_reason → orko_core::FinishReason, usage → orko_core::Usage

Preset + parsing

  • openai(model) constructor returning the engine configured with the base URL and env key
  • Quirks struct for per-provider differences (consumed by the other presets)
  • Fallible from_str("openai:gpt-4o-mini") → Result<_, orko_core::Error>

Constraints (workspace rules)

  • Tokio only behind the transport feature — never in a public signature
  • Deps flow down to orko-core only
  • --no-default-features must build clean (codec only, no transport)

Acceptance

  • Codec unit tests with no network: request JSON snapshots, SSE fixture → chunk-stream assertions (incl. multi-tool-call delta reassembly)
  • cargo clippy --all-targets --all-features -D warnings clean
  • examples/hello_agent.rs works against this preset (offline stub when OPENAI_API_KEY unset is acceptable)

Related

Tickets: #10
Tickets: #11
Tickets: #12
Tickets: #13
Tickets: #14
Tickets: #15
Tickets: #16
Tickets: #17
Tickets: #18
Tickets: #19
Tickets: #20
Tickets: #21
Tickets: #22
Tickets: #23
Tickets: #25
Tickets: #26
Tickets: #4
Tickets: #5
Tickets: #6
Tickets: #7
Tickets: #8
Tickets: #9

Discussion

  • Anonymous

    Anonymous - 2026-10-14

    Originally posted by: MayurK-cmd

    Hey can i work on this one?

     
  • Anonymous

    Anonymous - 2026-11-21

    Ticket changed by: SAMAD101

    • status: open --> closed
     

Log in to post a comment.