{"record":{"id":"96d1069104b34941","repo":"BoundaryML/baml","slug":"openai-transcription-field-temperature-must-be-a-number-or","errorCode":null,"errorMessage":"OpenAI transcription field `temperature` must be a number or string","messagePattern":"OpenAI transcription field `temperature` must be a number or string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/openai/types.rs","lineNumber":210,"sourceCode":"                        model,\n                        \"gpt-4o-transcribe\"\n                            | \"gpt-4o-mini-transcribe\"\n                            | \"gpt-4o-mini-transcribe-2025-12-15\"\n                            | \"gpt-4o-transcribe-diarize\"\n                    )) => Ok(Some(value.clone())),\n        Some(Value::String(value)) => bail!(\n            \"OpenAI transcription response_format `{value}` is not supported by model `{model}` in BAML; use `json`\"\n        ),\n        Some(_) => bail!(\"OpenAI transcription field `response_format` must be a string\"),\n        None => Ok(None),\n    }\n}\n\nfn optional_temperature(properties: &BamlMap<String, Value>) -> Result<Option<String>> {\n    match properties.get(\"temperature\") {\n        Some(Value::Number(value)) => Ok(Some(value.to_string())),\n        Some(Value::String(value)) => Ok(Some(value.clone())),\n        Some(_) => bail!(\"OpenAI transcription field `temperature` must be a number or string\"),\n        None => Ok(None),\n    }\n}\n\nfn filename_for_mime(mime: &str) -> String {\n    let subtype = mime\n        .split('/')\n        .next_back()\n        .unwrap_or(\"mpeg\")\n        .split(';')\n        .next()\n        .unwrap_or(\"mpeg\")\n        .trim()\n        .to_ascii_lowercase();\n    let extension = match subtype.as_str() {\n        \"mpeg\" | \"mp3\" | \"x-mp3\" => \"mp3\",\n        \"wav\" | \"wave\" | \"x-wav\" | \"vnd.wave\" => \"wav\",\n        \"mp4\" | \"m4a\" | \"x-m4a\" => \"m4a\",","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/openai/types.rs#L192-L228","documentation":"optional_temperature validates that the transcription client's `temperature` property, when present, is either a JSON number or a string; other types (bool, array, object, null literal in a wrong form) are rejected. BAML passes it through as a string to the OpenAI transcriptions API, which itself accepts only 0..1.","triggerScenarios":"Setting temperature in the BAML transcription client properties to a non-numeric, non-string JSON value such as true, [0.2], or {value: 0.2}.","commonSituations":"Boolean-looking config (temperature true), copying temperature from another provider's client that uses different typing, or templated values that resolve to objects.","solutions":["Set temperature to a numeric literal (e.g. temperature 0.2) or a quoted string (temperature \"0.2\").","Remove the temperature property to use the API default.","Also ensure the value is within OpenAI's accepted range 0.0-1.0 for transcription models."],"exampleFix":"// before\ntemperature true\n\n// after\ntemperature 0.2","handlingStrategy":"validation","validationCode":"if (props.temperature !== undefined) {\n  const t = props.temperature;\n  if (typeof t !== 'number' && typeof t !== 'string') {\n    throw new Error('temperature must be a number or string');\n  }\n  const n = Number(t);\n  if (Number.isNaN(n) || n < 0 || n > 1) {\n    throw new Error('temperature must be between 0 and 1');\n  }\n}","typeGuard":"const isValidTemperature = (v: unknown): v is number | string =>\n  typeof v === 'number' || typeof v === 'string';","tryCatchPattern":"try {\n  await baml.transcribe(...);\n} catch (e) {\n  if (String(e).includes('temperature')) {\n    console.error('Set temperature as a number (0.2) or quoted string (\"0.2\")');\n  }\n  throw e;\n}","preventionTips":["Write temperature as a numeric literal in config.","Keep the value in the 0.0-1.0 range supported by OpenAI transcription models.","Do not reuse temperature values from chat clients that accept different types."],"tags":["config","openai","transcription","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}