Repository Public
1# Reinforcement fine-tuning23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45Reinforcement fine-tuning (RFT) adapts an OpenAI reasoning model with a feedback signal you define. Like [supervised fine-tuning](https://developers.openai.com/api/docs/guides/supervised-fine-tuning), it tailors the model to your task. The difference is that instead of training on fixed “correct” answers, it relies on a programmable grader that scores every candidate response. The training algorithm then shifts the model’s weights, so high-scoring outputs become more likely and low-scoring ones fade.67OpenAI is winding down the fine-tuning platform. The platform is no longer8 accessible to new users, but existing users of the fine-tuning platform will9 be able to create training jobs for the coming months.10 1112 All fine-tuned models will remain available for inference until their base13 models are [deprecated](https://developers.openai.com/api/docs/deprecations). The full timeline is14 [here](https://developers.openai.com/api/docs/deprecations).1516171819<table>20<tbody>21<tr>22<th>How it works</th>23<th>Best for</th>24<th>Use with</th>25</tr>2627<tr>28<td>29Generate a response for a prompt, provide an expert grade for the result, and reinforce the model's chain-of-thought for higher-scored responses.3031Requires expert graders to agree on the ideal output from the model.3233</td>34<td>35- Complex domain-specific tasks that require advanced reasoning36- Medical diagnoses based on history and diagnostic guidelines37- Determining relevant passages from legal case law38</td>39<td>40`o4-mini-2025-04-16`4142**Reasoning models only**.4344</td>45</tr>46</tbody>47</table>4849This optimization lets you align the model with nuanced objectives like style, safety, or domain accuracy—with many [practical use cases](https://developers.openai.com/api/docs/guides/rft-use-cases) emerging. Run RFT in five steps:50511. Implement a [grader](https://developers.openai.com/api/docs/guides/graders) that assigns a numeric reward to each model response.521. Upload your prompt dataset and designate a validation split.531. Start the fine-tune job.541. Monitor and [evaluate](https://developers.openai.com/api/docs/guides/evals) checkpoints; revise data or grader if needed.551. Deploy the resulting model through the standard API.5657During training, the platform cycles through the dataset, samples several responses per prompt, scores them with the grader, and applies policy-gradient updates based on those rewards. The loop continues until we hit the end of your training data or you stop the job at a chosen checkpoint, producing a model optimized for the metric that matters to you.58596061## When should I use reinforcement fine-tuning?62636465It's useful to understand the strengths and weaknesses of reinforcement fine-tuning to identify opportunities and to avoid wasted effort.6667- **RFT works best with unambiguous tasks**. Check whether qualified human experts agree on the answers. If conscientious experts working independently (with access only to the same instructions and information as the model) do not converge on the same answers, the task may be too ambiguous and may benefit from revision or reframing.68- **Your task must be compatible with the grading options**. Review [grading options in the API](https://developers.openai.com/api/reference/resources/graders) first and verify it's possible to grade your task with them.69- **Your eval results must be variable enough to improve**. Run [evals](https://developers.openai.com/api/docs/guides/evals) before using RFT. If your eval scores between minimum and maximum possible scores, you'll have enough data to work with to reinforce positive answers. If the model you want to fine-tune scores at either the absolute minimum or absolute maximum score, RFT won't be useful to you.70- **Your model must have some success at the desired task**. Reinforcement fine-tuning makes gradual changes, sampling many answers and choosing the best ones. If a model has a 0% success rate at a given task, you cannot bootstrap to higher performance levels through RFT.71- **Your task should be guess-proof**. If the model can get a higher reward from a lucky guess, the training signal is too noisy, as the model can get the right answer with an incorrect reasoning process. Reframe your task to make guessing more difficult—for example, by expanding classes into subclasses or revising a multiple choice problem to take open-ended answers.7273See common use cases, specific implementations, and grader examples in the [reinforcement fine-tuning use case guide](https://developers.openai.com/api/docs/guides/rft-use-cases).7475767778798081## What is reinforcement learning?82838485Reinforcement learning is a branch of machine learning in which a model learns by acting, receiving feedback, and readjusting itself to maximise future feedback. Instead of memorising one “right” answer per example, the model explores many possible answers, observes a numeric reward for each, and gradually shifts its behaviour so the high-reward answers become more likely and the low-reward ones disappear. Over repeated rounds, the model converges on a policy—a rule for choosing outputs—that best satisfies the reward signal you define.8687In reinforcement fine-tuning (RFT), that reward signal comes from a custom grader that you define for your task. For every prompt in your dataset, the platform samples multiple candidate answers, runs your grader to score them, and applies a policy-gradient update that nudges the model toward answers with higher scores. This cycle—sample, grade, update—continues across the dataset (and successive epochs) until the model reliably optimizes for your grader’s understanding of quality. The grader encodes whatever you care about—accuracy, style, safety, or any metric—so the resulting fine-tuned model reflects those priorities and you don't have to manage reinforcement learning infrastructure.888990919293Reinforcement fine-tuning is supported on o-series reasoning models only, and94 currently only for [o4-mini](https://developers.openai.com/api/docs/models/o4-mini).9596## Example: LLM-powered security review9798To demonstrate reinforcement fine-tuning below, we'll fine-tune an [o4-mini](https://developers.openai.com/api/docs/models/o4-mini) model to provide expert answers about a fictional company's security posture, based on an internal company policy document. We want the model to return a JSON object that conforms to a specific schema with [Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs).99100Example input question:101102```103Do you have a dedicated security team?104```105106Using the internal policy document, we want the model to respond with JSON that has two keys:107108- `compliant`: A string `yes`, `no`, or `needs review`, indicating whether the company's policy covers the question.109- `explanation`: A string of text that briefly explains, based on the policy document, why the question is covered in the policy or why it's not covered.110111Example desired output from the model:112113```json114{115 "compliant": "yes",116 "explanation": "A dedicated security team follows strict protocols for handling incidents."117}118```119120Let's fine-tune a model with RFT to perform well at this task.121122## Define a grader123124To perform RFT, define a [grader](https://developers.openai.com/api/docs/guides/graders) to score the model's output during training, indicating the quality of its response. RFT uses the same set of graders as [evals](https://developers.openai.com/api/docs/guides/evals), which you may already be familiar with.125126In this example, we define [multiple graders](https://developers.openai.com/api/reference/resources/graders) to examine the properties of the JSON returned by our fine-tuned model:127128- The [`string_check`](https://developers.openai.com/api/reference/resources/graders) grader to ensure the proper `compliant` property has been set129- The [`score_model`](https://developers.openai.com/api/reference/resources/graders) grader to provide a score between zero and one for the explanation text, using another evaluator model130131We weight the output of each property equally in the `calculate_output` expression.132133Below is the JSON payload data we'll use for this grader in API requests. In both graders, we use `{{ }}` template syntax to refer to the relevant properties of both the `item` (the row of test data being used for evaluation) and `sample` (the model output generated during the training run).134135136137Grader configuration138139 Multi-grader configuration object140141```json142{143 "type": "multi",144 "graders": {145 "explanation": {146 "name": "Explanation text grader",147 "type": "score_model",148 "input": [149 {150 "role": "user",151 "type": "message",152 "content": "...see other tab for the full prompt..."153 }154 ],155 "model": "gpt-4o-2024-08-06"156 },157 "compliant": {158 "name": "compliant",159 "type": "string_check",160 "reference": "{{item.compliant}}",161 "operation": "eq",162 "input": "{{sample.output_json.compliant}}"163 }164 },165 "calculate_output": "0.5 * compliant + 0.5 * explanation"166}167```168169 170171 172173 174Grading prompt175176 Grading prompt in the grader config177178```markdown179# Overview180181Evaluate the accuracy of the model-generated answer based on the 182Copernicus Product Security Policy and an example answer. The response 183should align with the policy, cover key details, and avoid speculative 184or fabricated claims.185186Always respond with a single floating point number 0 through 1,187using the grading criteria below.188189## Grading Criteria:190- **1.0**: The model answer is fully aligned with the policy and factually correct.191- **0.75**: The model answer is mostly correct but has minor omissions or slight rewording that does not change meaning.192- **0.5**: The model answer is partially correct but lacks key details or contains speculative statements.193- **0.25**: The model answer is significantly inaccurate or missing important information.194- **0.0**: The model answer is completely incorrect, hallucinates policy details, or is irrelevant.195196## Copernicus Product Security Policy197198### Introduction199Protecting customer data is a top priority for Copernicus. Our platform is designed with industry-standard security and compliance measures to ensure data integrity, privacy, and reliability.200201### Data Classification202Copernicus safeguards customer data, which includes prompts, responses, file uploads, user preferences, and authentication configurations. Metadata, such as user IDs, organization IDs, IP addresses, and device details, is collected for security purposes and stored securely for monitoring and analytics.203204### Data Management205Copernicus utilizes cloud-based storage with strong encryption (AES-256) and strict access controls. Data is logically segregated to ensure confidentiality and access is restricted to authorized personnel only. Conversations and other customer data are never used for model training.206207### Data Retention208Customer data is retained only for providing core functionalities like conversation history and team collaboration. Customers can configure data retention periods, and deleted content is removed from our system within 30 days.209210### User Authentication & Access Control211Users authenticate via Single Sign-On (SSO) using an Identity Provider (IdP). Roles include Account Owner, Admin, and Standard Member, each with defined permissions. User provisioning can be automated through SCIM integration.212213### Compliance & Security Monitoring214- **Compliance API**: Logs interactions, enabling data export and deletion.215- **Audit Logging**: Ensures transparency for security audits.216- **HIPAA Support**: Business Associate Agreements (BAAs) available for customers needing healthcare compliance.217- **Security Monitoring**: 24/7 monitoring for threats and suspicious activity.218- **Incident Response**: A dedicated security team follows strict protocols for handling incidents.219220### Infrastructure Security221- **Access Controls**: Role-based authentication with multi-factor security.222- **Source Code Security**: Controlled code access with mandatory reviews before deployment.223- **Network Security**: Web application firewalls and strict ingress/egress controls to prevent unauthorized access.224- **Physical Security**: Data centers have controlled access, surveillance, and environmental risk management.225226### Bug Bounty Program227Security researchers are encouraged to report vulnerabilities through our Bug Bounty Program for responsible disclosure and rewards.228229### Compliance & Certifications230Copernicus maintains compliance with industry standards, including SOC 2 and GDPR. Customers can access security reports and documentation via our Security Portal.231232### Conclusion233Copernicus prioritizes security, privacy, and compliance. For inquiries, contact your account representative or visit our Security Portal.234235## Examples236237### Example 1: GDPR Compliance238**Reference Answer**: 'Copernicus maintains compliance with industry standards, including SOC 2 and GDPR. Customers can access security reports and documentation via our Security Portal.'239240**Model Answer 1**: 'Yes, Copernicus is GDPR compliant and provides compliance documentation via the Security Portal.' 241**Score: 1.0** (fully correct)242243**Model Answer 2**: 'Yes, Copernicus follows GDPR standards.'244**Score: 0.75** (mostly correct but lacks detail about compliance reports)245246**Model Answer 3**: 'Copernicus may comply with GDPR but does not provide documentation.'247**Score: 0.5** (partially correct, speculative about compliance reports)248249**Model Answer 4**: 'Copernicus does not follow GDPR standards.'250**Score: 0.0** (factually incorrect)251252### Example 2: Encryption in Transit253**Reference Answer**: 'The Copernicus Product Security Policy states that data is stored with strong encryption (AES-256) and that network security measures include web application firewalls and strict ingress/egress controls. However, the policy does not explicitly mention encryption of data in transit (e.g., TLS encryption). A review is needed to confirm whether data transmission is encrypted.'254255**Model Answer 1**: 'Data is encrypted at rest using AES-256, but a review is needed to confirm encryption in transit.'256**Score: 1.0** (fully correct)257258**Model Answer 2**: 'Yes, Copernicus encrypts data in transit and at rest.'259**Score: 0.5** (partially correct, assumes transit encryption without confirmation)260261**Model Answer 3**: 'All data is protected with encryption.'262**Score: 0.25** (vague and lacks clarity on encryption specifics)263264**Model Answer 4**: 'Data is not encrypted in transit.'265**Score: 0.0** (factually incorrect)266267Reference Answer: {{item.explanation}}268Model Answer: {{sample.output_json.explanation}}269```270271272273## Prepare your dataset274275To create an RFT fine-tune, you'll need both a training and test dataset. Both the training and test datasets will share the same [JSONL format](https://jsonlines.org/). Each line in the JSONL data file will contain a `messages` array, along with any additional fields required to grade the output from the model. The full specification for RFT dataset [can be found here](https://developers.openai.com/api/reference/resources/fine_tuning).276277In our case, in addition to the `messages` array, each line in our JSONL file also needs `compliant` and `explanation` properties, which we can use as reference values to test the fine-tuned model's Structured Output.278279A single line in our training and test datasets looks like this as indented JSON:280281```json282{283 "messages": [284 {285 "role": "user",286 "content": "Do you have a dedicated security team?"287 }288 ],289 "compliant": "yes",290 "explanation": "A dedicated security team follows strict protocols for handling incidents."291}292```293294Below, find some JSONL data you can use for both training and testing when you create your fine-tune job. Note that these datasets are for illustration purposes only—in your real test data, strive for diverse and representative inputs for your application.295296**Training set**297298```299{"messages":[{"role":"user","content":"Do you have a dedicated security team?"}],"compliant":"yes","explanation":"A dedicated security team follows strict protocols for handling incidents."}300{"messages":[{"role":"user","content":"Have you undergone third-party security audits or penetration testing in the last 12 months?"}],"compliant":"needs review","explanation":"The policy does not explicitly mention undergoing third-party security audits or penetration testing. It only mentions SOC 2 and GDPR compliance."}301{"messages":[{"role":"user","content":"Is your software SOC 2, ISO 27001, or similarly certified?"}],"compliant":"yes","explanation":"The policy explicitly mentions SOC 2 compliance."}302```303304**Test set**305306```307{"messages":[{"role":"user","content":"Will our data be encrypted at rest?"}],"compliant":"yes","explanation":"Copernicus utilizes cloud-based storage with strong encryption (AES-256) and strict access controls."}308{"messages":[{"role":"user","content":"Will data transmitted to/from your services be encrypted in transit?"}],"compliant":"needs review","explanation":"The policy does not explicitly mention encryption of data in transit. It focuses on encryption in cloud storage."}309{"messages":[{"role":"user","content":"Do you enforce multi-factor authentication (MFA) internally?"}],"compliant":"yes","explanation":"The policy explicitly mentions role-based authentication with multi-factor security."}310```311312313314### How much training data is needed?315316317318Start small—between several dozen and a few hundred examples—to determine the usefulness of RFT before investing in a large dataset. For product safety reasons, the training set must first pass through an automated screening process. Large datasets take longer to process. This screening process begins when you start a fine-tuning job with a file, not upon initial file upload. Once a file has successfully completed screening, you can use it repeatedly without delay.319320Dozens of examples can be meaningful as long as they're high quality. After screening, more data is better, as long as it remains high quality. With larger datasets, you can use a higher batch size, which tends to improve training stability.321322Your training file can contain a maximum of 50,000 examples. Test datasets can contain a maximum of 1,000 examples. Test datasets also go through automated screening.323324325326327328### Upload your files329330The process for uploading RFT training and test data files is the same as [supervised fine-tuning](https://developers.openai.com/api/docs/guides/supervised-fine-tuning). Upload your training data to OpenAI either through the [API](https://developers.openai.com/api/reference/resources/files/methods/create) or [using our UI](https://platform.openai.com/storage). Files must be uploaded with a purpose of `fine-tune` in order to be used with fine-tuning.331332**You need file IDs for both your test and training data files** to create a fine-tune job.333334## Create a fine-tune job335336Create a fine-tune job using either the [API](https://developers.openai.com/api/reference/resources/fine_tuning) or [fine-tuning dashboard](https://platform.openai.com/finetune). To do this, you need:337338- File IDs for both your training and test datasets339- The grader configuration we created earlier340- The model ID you want to use as a base for fine-tuning (we'll use `o4-mini-2025-04-16`)341- If you're fine-tuning a model that will return JSON data as a structured output, you need the JSON schema for the returned object as well (see below)342- Optionally, any hyperparameters you want to configure for the fine-tune343- To qualify for [data sharing inference pricing](https://developers.openai.com/api/docs/pricing#fine-tuning), you need to first [share evaluation and fine-tuning data](https://help.openai.com/en/articles/10306912-sharing-feedback-evaluation-and-fine-tuning-data-and-api-inputs-and-outputs-with-openai#h_c93188c569) with OpenAI before creating the job344345### Structured Outputs JSON schema346347If you're fine-tuning a model to return [Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs), provide the JSON schema being used to format the output. See a valid JSON schema for our security interview use case:348349```json350{351 "type": "json_schema",352 "json_schema": {353 "name": "security_assistant",354 "strict": true,355 "schema": {356 "type": "object",357 "properties": {358 "compliant": { "type": "string" },359 "explanation": { "type": "string" }360 },361 "required": ["compliant", "explanation"],362 "additionalProperties": false363 }364 }365}366```367368369370#### Generating a JSON schema from a Pydantic model371372373374To simplify JSON schema generation, start from a [Pydantic BaseModel](https://docs.pydantic.dev/latest/api/base_model/) class:3753761. Define your class3771. Use `to_strict_json_schema` from the OpenAI library to generate a valid schema3781. Wrap the schema in a dictionary with `type` and `name` keys, and set `strict` to true3791. Take the resulting object and supply it as the `response_format` in your RFT job380381```python382from openai.lib._pydantic import to_strict_json_schema383from pydantic import BaseModel384385386class MyCustomClass(BaseModel):387 name: str388 age: int389390391# Note: Do not use MyCustomClass.model_json_schema() in place of392# to_strict_json_schema as it is not equivalent393schema = to_strict_json_schema(MyCustomClass)394395response_format = dict(396 type="json_schema",397 json_schema=dict(name=MyCustomClass.__name__, strict=True, schema=schema),398)399```400401402403404405406### Create a job with the API407408Configuring a job with the API has a lot of moving parts, so many users prefer to configure them in the [fine-tuning dashboard UI](https://platform.openai.com/finetune). However, here's a complete API request to kick off a fine-tune job with all the configuration we've set up in this guide so far:409410```bash411curl https://api.openai.com/v1/fine_tuning/jobs \412 -H "Content-Type: application/json" \413 -H "Authorization: Bearer $OPENAI_API_KEY" \414 -d '{415 "training_file": "file-2STiufDaGXWCnT6XUBUEHW",416 "validation_file": "file-4TcgH85ej7dFCjZ1kThCYb",417 "model": "o4-mini-2025-04-16",418 "method": {419 "type": "reinforcement",420 "reinforcement": {421 "grader": {422 "type": "multi",423 "graders": {424 "explanation": {425 "name": "Explanation text grader",426 "type": "score_model",427 "input": [428 {429 "role": "user",430 "type": "message",431 "content": "# Overview\n\nEvaluate the accuracy of the model-generated answer based on the \nCopernicus Product Security Policy and an example answer. The response \nshould align with the policy, cover key details, and avoid speculative \nor fabricated claims.\n\nAlways respond with a single floating point number 0 through 1,\nusing the grading criteria below.\n\n## Grading Criteria:\n- **1.0**: The model answer is fully aligned with the policy and factually correct.\n- **0.75**: The model answer is mostly correct but has minor omissions or slight rewording that does not change meaning.\n- **0.5**: The model answer is partially correct but lacks key details or contains speculative statements.\n- **0.25**: The model answer is significantly inaccurate or missing important information.\n- **0.0**: The model answer is completely incorrect, hallucinates policy details, or is irrelevant.\n\n## Copernicus Product Security Policy\n\n### Introduction\nProtecting customer data is a top priority for Copernicus. Our platform is designed with industry-standard security and compliance measures to ensure data integrity, privacy, and reliability.\n\n### Data Classification\nCopernicus safeguards customer data, which includes prompts, responses, file uploads, user preferences, and authentication configurations. Metadata, such as user IDs, organization IDs, IP addresses, and device details, is collected for security purposes and stored securely for monitoring and analytics.\n\n### Data Management\nCopernicus utilizes cloud-based storage with strong encryption (AES-256) and strict access controls. Data is logically segregated to ensure confidentiality and access is restricted to authorized personnel only. Conversations and other customer data are never used for model training.\n\n### Data Retention\nCustomer data is retained only for providing core functionalities like conversation history and team collaboration. Customers can configure data retention periods, and deleted content is removed from our system within 30 days.\n\n### User Authentication & Access Control\nUsers authenticate via Single Sign-On (SSO) using an Identity Provider (IdP). Roles include Account Owner, Admin, and Standard Member, each with defined permissions. User provisioning can be automated through SCIM integration.\n\n### Compliance & Security Monitoring\n- **Compliance API**: Logs interactions, enabling data export and deletion.\n- **Audit Logging**: Ensures transparency for security audits.\n- **HIPAA Support**: Business Associate Agreements (BAAs) available for customers needing healthcare compliance.\n- **Security Monitoring**: 24/7 monitoring for threats and suspicious activity.\n- **Incident Response**: A dedicated security team follows strict protocols for handling incidents.\n\n### Infrastructure Security\n- **Access Controls**: Role-based authentication with multi-factor security.\n- **Source Code Security**: Controlled code access with mandatory reviews before deployment.\n- **Network Security**: Web application firewalls and strict ingress/egress controls to prevent unauthorized access.\n- **Physical Security**: Data centers have controlled access, surveillance, and environmental risk management.\n\n### Bug Bounty Program\nSecurity researchers are encouraged to report vulnerabilities through our Bug Bounty Program for responsible disclosure and rewards.\n\n### Compliance & Certifications\nCopernicus maintains compliance with industry standards, including SOC 2 and GDPR. Customers can access security reports and documentation via our Security Portal.\n\n### Conclusion\nCopernicus prioritizes security, privacy, and compliance. For inquiries, contact your account representative or visit our Security Portal.\n\n## Examples\n\n### Example 1: GDPR Compliance\n**Reference Answer**: Copernicus maintains compliance with industry standards, including SOC 2 and GDPR. Customers can access security reports and documentation via our Security Portal.\n\n**Model Answer 1**: Yes, Copernicus is GDPR compliant and provides compliance documentation via the Security Portal. \n**Score: 1.0** (fully correct)\n\n**Model Answer 2**: Yes, Copernicus follows GDPR standards.\n**Score: 0.75** (mostly correct but lacks detail about compliance reports)\n\n**Model Answer 3**: Copernicus may comply with GDPR but does not provide documentation.\n**Score: 0.5** (partially correct, speculative about compliance reports)\n\n**Model Answer 4**: Copernicus does not follow GDPR standards.\n**Score: 0.0** (factually incorrect)\n\n### Example 2: Encryption in Transit\n**Reference Answer**: The Copernicus Product Security Policy states that data is stored with strong encryption (AES-256) and that network security measures include web application firewalls and strict ingress/egress controls. However, the policy does not explicitly mention encryption of data in transit (e.g., TLS encryption). A review is needed to confirm whether data transmission is encrypted.\n\n**Model Answer 1**: Data is encrypted at rest using AES-256, but a review is needed to confirm encryption in transit.\n**Score: 1.0** (fully correct)\n\n**Model Answer 2**: Yes, Copernicus encrypts data in transit and at rest.\n**Score: 0.5** (partially correct, assumes transit encryption without confirmation)\n\n**Model Answer 3**: All data is protected with encryption.\n**Score: 0.25** (vague and lacks clarity on encryption specifics)\n\n**Model Answer 4**: Data is not encrypted in transit.\n**Score: 0.0** (factually incorrect)\n\nReference Answer: {{item.explanation}}\nModel Answer: {{sample.output_json.explanation}}\n"432 }433 ],434 "model": "gpt-4o-2024-08-06"435 },436 "compliant": {437 "name": "compliant",438 "type": "string_check",439 "reference": "{{item.compliant}}",440 "operation": "eq",441 "input": "{{sample.output_json.compliant}}"442 }443 },444 "calculate_output": "0.5 * compliant + 0.5 * explanation"445 },446 "response_format": {447 "type": "json_schema",448 "json_schema": {449 "name": "security_assistant",450 "strict": true,451 "schema": {452 "type": "object",453 "properties": {454 "compliant": {455 "type": "string"456 },457 "explanation": {458 "type": "string"459 }460 },461 "required": [462 "compliant",463 "explanation"464 ],465 "additionalProperties": false466 }467 }468 },469 "hyperparameters": {470 "reasoning_effort": "medium"471 }472 }473 }474}'475```476477478This request returns a [fine-tuning job object](https://developers.openai.com/api/reference/resources/fine_tuning), which includes a job `id`. Use this ID to monitor the progress of your job and retrieve the fine-tuned model when the job is complete.479480To qualify for [data sharing inference pricing](https://developers.openai.com/api/docs/pricing#fine-tuning), make sure to [share evaluation and fine-tuning data](https://help.openai.com/en/articles/10306912-sharing-feedback-evaluation-and-fine-tuning-data-and-api-inputs-and-outputs-with-openai#h_c93188c569) with OpenAI before creating the job. You can verify the job was marked as shared by confirming `shared_with_openai` is set to `true`.481482### Monitoring your fine-tune job483484Fine-tuning jobs take some time to complete, and RFT jobs tend to take longer than SFT or DPO jobs. To monitor the progress of your fine-tune job, use the [fine-tuning dashboard](https://platform.openai.com/finetune) or the [API](https://developers.openai.com/api/reference/resources/fine_tuning).485486#### Reward metrics487488For reinforcement fine-tuning jobs, the primary metrics are the per-step **reward** metrics. These metrics indicate how well your model is performing on the training data. They're calculated by the graders you defined in your job configuration. These are two separate top-level reward metrics:489490- `train_reward_mean`: The average reward across the samples taken from all datapoints in the current step. Because the specific datapoints in a batch change with each step, `train_reward_mean` values across different steps are not directly comparable and the specific values can fluctuate drastically from step to step.491- `valid_reward_mean`: The average reward across the samples taken from all datapoints in the validation set, which is a more stable metric.492493494495Find a full description of all training metrics in the [training metrics](#training-metrics) section.496497#### Pausing and resuming jobs498499To evaluate the current state of the model when your job is only partially finished, **pause** the job to stop the training process and produce a checkpoint at the current step. You can use this checkpoint to evaluate the model on a held-out test set. If the results look good, **resume** the job to continue training from that checkpoint. Learn more in [pausing and resuming jobs](#pausing-and-resuming-jobs).500501#### Evals integration502503Reinforcement fine-tuning jobs are integrated with our [evals product](https://developers.openai.com/api/docs/guides/evals). When you make a reinforcement fine-tuning job, a new eval is automatically created and associated with the job. As validation steps are performed, we combine the input prompts, model samples, and grader outputs to make a new [eval run](https://developers.openai.com/api/docs/guides/evals#creating-an-eval-run) for that step.504505Learn more about the evals integration in the [appendix](#evals-integration-details) section below.506507## Evaluate the results508509By the time your fine-tuning job finishes, you should have a decent idea of how well the model is performing based on the mean reward value on the validation set. However, it's possible that the model has either _overfit_ to the training data or has learned to [reward hack](https://en.wikipedia.org/wiki/Reward_hacking) your grader, which allows it to produce high scores without actually being correct. Before deploying your model, inspect its behavior on a representative set of prompts to ensure it behaves how you expect.510511Understanding the model's behavior can be done quickly by inspecting the evals associated with the fine-tuning job. Specifically, pay close attention to the run made for the final training step to see the end model's behavior. You can also use the evals product to compare the final run to earlier runs and see how the model's behavior has changed over the course of training.512513### Try using your fine-tuned model514515Evaluate your newly optimized model by using it! When the fine-tuned model finishes training, use its ID in either the [Responses](https://developers.openai.com/api/reference/resources/responses) or [Chat Completions](https://developers.openai.com/api/reference/resources/chat) API, just as you would an OpenAI base model.516517518519Use your model in the Playground520521 5225231. Navigate to your fine-tuning job in [the dashboard](https://platform.openai.com/finetune).5241. In the right pane, navigate to **Output model** and copy the model ID. It should start with `ft:…`5251. Open the [Playground](https://platform.openai.com/playground).5261. In the **Model** dropdown menu, paste the model ID. Here, you should also see other fine-tuned models you've created.5271. Run some prompts and see how your fine-tuned performs!528529530 531532 533534 535Use your model with an API call536537 538539```bash540curl https://api.openai.com/v1/responses \541 -H "Content-Type: application/json" \542 -H "Authorization: Bearer $OPENAI_API_KEY" \543 -d '{544 "model": "ft:gpt-4.1-nano-2025-04-14:openai::BTz2REMH",545 "input": "What is 4+4?"546 }'547```548549550551### Use checkpoints if needed552553Checkpoints are models you can use that are created before the final step of the training process. For RFT, OpenAI creates a full model checkpoint at each validation step and keeps the three with the highest `valid_reward_mean` scores. Checkpoints are useful for evaluating the model at different points in the training process and comparing performance at different steps.554555556557Find checkpoints in the dashboard558559 5605611. Navigate to the [fine-tuning dashboard](https://platform.openai.com/finetune).5621. In the left panel, select the job you want to investigate. Wait until it succeeds.5631. In the right panel, scroll to the list of checkpoints.5641. Hover over any checkpoint to see a link to launch in the Playground.5651. Test the checkpoint model's behavior by prompting it in the Playground.566567568 569570 571572 573Query the API for checkpoints574575 5765771. Wait until a job succeeds, which you can verify by [querying the status of a job](https://developers.openai.com/api/reference/resources/fine_tuning).5781. [Query the checkpoints endpoint](https://developers.openai.com/api/reference/resources/fine_tuning/subresources/jobs/subresources/checkpoints/methods/list) with your fine-tuning job ID to access a list of model checkpoints for the fine-tuning job.5791. Find the `fine_tuned_model_checkpoint` field for the name of the model checkpoint.5801. Use this model just like you would the final fine-tuned model.581582The checkpoint object contains `metrics` data to help you determine the usefulness of this model. As an example, the response looks like this:583584```json585{586 "object": "fine_tuning.job.checkpoint",587 "id": "ftckpt_zc4Q7MP6XxulcVzj4MZdwsAB",588 "created_at": 1519129973,589 "fine_tuned_model_checkpoint": "ft:gpt-3.5-turbo-0125:my-org:custom-suffix:96olL566:ckpt-step-2000",590 "metrics": {591 "full_valid_loss": 0.134,592 "full_valid_mean_token_accuracy": 0.874593 },594 "fine_tuning_job_id": "ftjob-abc123",595 "step_number": 2000596}597```598599Each checkpoint specifies:600601- `step_number`: The step at which the checkpoint was created (where each epoch is number of steps in the training set divided by the batch size)602- `metrics`: An object containing the metrics for your fine-tuning job at the step when the checkpoint was created603604605606## Safety checks607608Before launching in production, review and follow the following safety information.609610611612### How we assess for safety613614615616Once a fine-tuning job is completed, we assess the resulting model’s behavior across 13 distinct safety categories. Each category represents a critical area where AI outputs could potentially cause harm if not properly controlled.617618| Name | Description |619| :--------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |620| advice | Advice or guidance that violates our policies. |621| harassment/threatening | Harassment content that also includes violence or serious harm towards any target. |622| hate | Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. Hateful content aimed at non-protected groups (e.g., chess players) is harassment. |623| hate/threatening | Hateful content that also includes violence or serious harm towards the targeted group based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. |624| highly-sensitive | Highly sensitive data that violates our policies. |625| illicit | Content that gives advice or instruction on how to commit illicit acts. A phrase like "how to shoplift" would fit this category. |626| propaganda | Praise or assistance for ideology that violates our policies. |627| self-harm/instructions | Content that encourages performing acts of self-harm, such as suicide, cutting, and eating disorders, or that gives instructions or advice on how to commit such acts. |628| self-harm/intent | Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm, such as suicide, cutting, and eating disorders. |629| sensitive | Sensitive data that violates our policies. |630| sexual/minors | Sexual content that includes an individual who is under 18 years old. |631| sexual | Content meant to arouse sexual excitement, such as the description of sexual activity, or that promotes sexual services (excluding sex education and wellness). |632| violence | Content that depicts death, violence, or physical injury. |633634Each category has a predefined pass threshold; if too many evaluated examples in a given category fail, OpenAI blocks the fine-tuned model from deployment. If your fine-tuned model does not pass the safety checks, OpenAI sends a message in the fine-tuning job explaining which categories don't meet the required thresholds. You can view the results in the moderation checks section of the fine-tuning job.635636637638639640641642### How to pass safety checks643644645646In addition to reviewing any failed safety checks in the fine-tuning job object, you can retrieve details about which categories failed by querying the [fine-tuning API events endpoint](https://developers.openai.com/api/reference/resources/fine_tuning/subresources/jobs/methods/list). Look for events of type `moderation_checks` for details about category results and enforcement. This information can help you narrow down which categories to target for retraining and improvement. The [model spec](https://cdn.openai.com/spec/model-spec-2024-05-08.html#overview) has rules and examples that can help identify areas for additional training data.647648While these evaluations cover a broad range of safety categories, conduct your own evaluations of the fine-tuned model to ensure it's appropriate for your use case.649650651652653654## Next steps655656Now that you know the basics of reinforcement fine-tuning, explore other fine-tuning methods.657658[Supervised fine-tuning659660661662 Fine-tune a model by providing correct outputs for sample inputs.](https://developers.openai.com/api/docs/guides/supervised-fine-tuning)663664[Vision fine-tuning665666667668 Learn to fine-tune for computer vision with image inputs.](https://developers.openai.com/api/docs/guides/vision-fine-tuning)669670[Direct preference optimization671672673674 Fine-tune a model using direct preference optimization (DPO).](https://developers.openai.com/api/docs/guides/direct-preference-optimization)675676## Appendix677678### Training metrics679680Reinforcement fine-tuning jobs publish per-step training metrics as [fine-tuning events](https://developers.openai.com/api/reference/resources/fine_tuning). Pull these metrics through the [API](https://developers.openai.com/api/reference/resources/fine_tuning/subresources/jobs/methods/list) or view them as graphs and charts in the [fine-tuning dashboard](https://platform.openai.com/finetune).681682Learn more about training metrics below.683684685686#### Full example training metrics687688689690Below is an example metric event from a real reinforcement fine-tuning job. The various fields in this payload will be discussed in the following sections.691692```json693{694 "object": "fine_tuning.job.event",695 "id": "ftevent-Iq5LuNLDsac1C3vzshRBuBIy",696 "created_at": 1746679539,697 "level": "info",698 "message": "Step 10/20 , train mean reward=0.42, full validation mean reward=0.68, full validation mean parse error=0.00",699 "data": {700 "step": 10,701 "usage": {702 "graders": [703 {704 "name": "basic_model_grader",705 "type": "score_model",706 "model": "gpt-4o-2024-08-06",707 "train_prompt_tokens_mean": 241.0,708 "valid_prompt_tokens_mean": 241.0,709 "train_prompt_tokens_count": 120741.0,710 "valid_prompt_tokens_count": 4820.0,711 "train_completion_tokens_mean": 138.52694610778443,712 "valid_completion_tokens_mean": 140.5,713 "train_completion_tokens_count": 69402.0,714 "valid_completion_tokens_count": 2810.0715 }716 ],717 "samples": {718 "train_reasoning_tokens_mean": 3330.017964071856,719 "valid_reasoning_tokens_mean": 1948.9,720 "train_reasoning_tokens_count": 1668339.0,721 "valid_reasoning_tokens_count": 38978.0722 }723 },724 "errors": {725 "graders": [726 {727 "name": "basic_model_grader",728 "type": "score_model",729 "train_other_error_mean": 0.0,730 "valid_other_error_mean": 0.0,731 "train_other_error_count": 0.0,732 "valid_other_error_count": 0.0,733 "train_sample_parse_error_mean": 0.0,734 "valid_sample_parse_error_mean": 0.0,735 "train_sample_parse_error_count": 0.0,736 "valid_sample_parse_error_count": 0.0,737 "train_invalid_variable_error_mean": 0.0,738 "valid_invalid_variable_error_mean": 0.0,739 "train_invalid_variable_error_count": 0.0,740 "valid_invalid_variable_error_count": 0.0741 }742 ]743 },744 "scores": {745 "graders": [746 {747 "name": "basic_model_grader",748 "type": "score_model",749 "train_reward_mean": 0.4471057884231537,750 "valid_reward_mean": 0.675751 }752 ],753 "train_reward_mean": 0.4215686274509804,754 "valid_reward_mean": 0.675755 },756 "timing": {757 "step": {758 "eval": 101.69386267662048,759 "sampling": 226.82190561294556,760 "training": 402.43121099472046,761 "full_iteration": 731.5038568973541762 },763 "graders": [764 {765 "name": "basic_model_grader",766 "type": "score_model",767 "train_execution_latency_mean": 2.6894934929297594,768 "valid_execution_latency_mean": 4.141402995586395769 }770 ]771 },772 "total_steps": 20,773 "train_mean_reward": 0.4215686274509804,774 "reasoning_tokens_mean": 3330.017964071856,775 "completion_tokens_mean": 3376.0019607843137,776 "full_valid_mean_reward": 0.675,777 "mean_unresponsive_rewards": 0.0,778 "model_graders_token_usage": {779 "gpt-4o-2024-08-06": {780 "eval_cached_tokens": 0,781 "eval_prompt_tokens": 4820,782 "train_cached_tokens": 0,783 "train_prompt_tokens": 120741,784 "eval_completion_tokens": 2810,785 "train_completion_tokens": 69402786 }787 },788 "full_valid_mean_parse_error": 0.0,789 "valid_reasoning_tokens_mean": 1948.9790 },791 "type": "metrics"792 },793```794795796797798799800801#### Score metrics802803804805The top-level metrics to watch are `train_reward_mean` and `valid_reward_mean`, which indicate the average reward assigned by your graders across all samples in the training and validation datasets, respectively.806807Additionally, if you use a [multi-grader](https://developers.openai.com/api/reference/resources/graders) configuration, per-grader train and validation reward metrics will be published as well. These metrics are included under the `event.data.scores` object in the fine-tuning events object, with one entry per grader. The per-grader metrics are useful for understanding how the model is performing on each individual grader, and can help you identify if the model is overfitting to one grader or another.808809From the fine-tuning dashboard, the individual grader metrics will be displayed in their own graph below the overall `train_reward_mean` and `valid_reward_mean` metrics.810811812813814815816817818819#### Usage metrics820821822823An important characteristic of a reasoning model is the number of reasoning tokens it uses before responding to a prompt. Often, during training, the model will drastically change the average number of reasoning tokens it uses to respond to a prompt. This is a sign that the model is changing its behavior in response to the reward signal. The model may learn to use fewer reasoning tokens to achieve the same reward, or it may learn to use more reasoning tokens to achieve a higher reward.824825You can monitor the `train_reasoning_tokens_mean` and `valid_reasoning_tokens_mean` metrics to see how the model is changing its behavior over time. These metrics are the average number of reasoning tokens used by the model to respond to a prompt in the training and validation datasets, respectively. You can also view the mean reasoning token count in the fine-tuning dashboard under the "Reasoning Tokens" chart.826827828829If you are using [model graders](https://developers.openai.com/api/docs/guides/graders#model-graders), you will likely want to monitor the token usage of these graders. Per-grader token usage statistics are available under the `event.data.usage.graders` object, and are broken down into:830831- `train_prompt_tokens_mean`832- `train_prompt_tokens_count`833- `train_completion_tokens_mean`834- `train_completion_tokens_count`.835836The `_mean` metrics represent the average number of tokens used by the grader to process all prompts in the current step, while the `_count` metrics represent the total number of tokens used by the grader across all samples in the current step. The per-step token usage is also displayed on the fine-tuning dashboard under the "Grading Token Usage" chart.837838839840841842843844845846#### Timing metrics847848849850We include various metrics that help you understand how long each step of the training process is taking and how different parts of the training process are contributing to the per-step timing.851852These metrics are available under the `event.data.timing` object, and are broken down into `step` and `graders` fields.853854The `step` field contains the following metrics:855856- `sampling`: The time taken to sample the model outputs (rollouts) for the current step.857- `training`: The time taken to train the model (backpropagation) for the current step.858- `eval`: The time taken to evaluate the model on the full validation set.859- `full_iteration`: The total time taken for the current step, including the above 3 metrics plus any additional overhead.860861The step timing metrics are also displayed on the fine-tuning dashboard under the "Per Step Duration" chart.862863864865The `graders` field contains timing information that details the time taken to execute each grader for the current step. Each grader will have its own timing under the `train_execution_latency_mean` and `valid_execution_latency_mean` metrics, which represent the average time taken to execute the grader on the training and validation datasets, respectively.866867Graders are executed in parallel with a concurrency limit, so it is not always clear how individual grader latency adds up to the total time taken for grading. However, it is generally true that graders which take longer to execute individually will cause a job to execute more slowly. This means that slower model graders will cause the job to take longer to complete, and more expensive python code will do the same. The fastest graders generally are `string_check` and `text_similarity` as those are executed local to the training loop.868869870871872873### Evals integration details874875Reinforcement fine-tuning jobs are directly integrated with our [evals product](https://developers.openai.com/api/docs/guides/evals). When you make a reinforcement fine-tuning job, a new eval is automatically created and associated with the job.876877As validation steps are performed, the input prompts, model samples, grader outputs, and more metadata will be combined to make a new [eval run](https://developers.openai.com/api/docs/guides/evals#creating-an-eval-run) for that step. At the end of the job, you will have one run for each validation step. This allows you to compare the performance of the model at different steps, and to see how the model's behavior has changed over the course of training.878879You can find the eval associated with your fine-tuning job by viewing your job on the fine-tuning dashboard, or by finding the `eval_id` field on the [fine-tuning job object](https://developers.openai.com/api/reference/resources/fine_tuning).880881The evals product is useful for inspecting the outputs of the model on specific datapoints, to get an understanding for how the model is behaving in different scenarios. It can help you figure out which slice of your dataset the model is performing poorly on which can help you identify areas for improvement in your training data.882883The evals product can also help you find areas of improvement for your graders by finding areas where the grader is either overly lenient or overly harsh on the model outputs.884885### Pausing and resuming jobs886887You can pause a fine-tuning job at any time by using the [fine-tuning jobs API](https://developers.openai.com/api/reference/resources/fine_tuning). Calling the pause API will tell the training process to create a new model snapshot, stop training, and put the job into a "Paused" state. The model snapshot will go through a normal safety screening process after which it will be available for you to use throughout the OpenAI platform as a normal fine-tuned model.888889If you wish to continue the training process for a paused job, you can do so by using the [fine-tuning jobs API](https://developers.openai.com/api/reference/resources/fine_tuning). This will resume the training process from the last checkpoint created when the job was paused and will continue training until the job is either completed or paused again.890891### Grading with Tools892893If you are training your model to [perform tool calls](https://developers.openai.com/api/docs/guides/function-calling), you will need to:8948951. Provide the set of tools available for your model to call on each datapoint in the RFT training dataset. More info here in the [dataset API reference](https://developers.openai.com/api/reference/resources/fine_tuning).8962. Configure your grader to assign rewards based on the contents of the tool calls made by the model. Information on grading tools calls can be found [here in the grading docs](https://developers.openai.com/api/docs/guides/graders/#sample-namespace)897898### Billing details899900Reinforcement fine-tuning jobs are billed based on the amount of time spent training, as well as the number of tokens used by the model during training. We only bill for time spent in the core training loop, not for time spent preparing the training data, validating datasets, waiting in queues, running safety evals, or other overhead.901902Details on exactly how we bill for reinforcement fine-tuning jobs can be found in this [help center article](https://help.openai.com/en/articles/11323177-billing-guide-for-the-reinforcement-fine-tuning-api).903904### Training errors905906Reinforcement fine-tuning is a complex process with many moving parts, and there are many places where things can go wrong. We publish various error metrics to help you understand what is going wrong in your job, and how to fix it. In general, we try to avoid failing a job entirely unless a very serious error occurs. When errors do occur, they often happen during the grading step. Errors during grading often happen either to the model outputting a sample that the grader doesn't know how to handle, the grader failing to execute properly due to some sort of system error, or due to a bug in the grading logic itself.907908The error metrics are available under the `event.data.errors` object, and are aggregated into counts and rates rolled up per-grader. We also display rates and counts of errors on the fine-tuning dashboard.909910911912#### Grader errors913914915916#### Generic grading errors917918The grader errors are broken down into the following categories, and they exist in both `train_` (for training data) and `valid_` (for validation data) versions:919920- `sample_parse_error_mean`: The average number of samples that failed to parse correctly. This often happens when the model fails to output valid JSON or adhere to a provided response format correctly. A small percentage of these errors, especially early in the training process, is normal. If you see a large number of these errors, it is likely that the response format of the model is not configured correctly or that your graders are misconfigured and looking for incorrect fields.921- `invalid_variable_error_mean`: These errors occur when you attempt to reference a variable via a template that cannot be found either in the current datapoint or in the current model sample. This can happen if the model fails to provide output in the correct response format, or if your grader is misconfigured.922- `other_error_mean`: This is a catch-all for any other errors that occur during grading. These errors are often caused by bugs in the grading logic itself, or by system errors that occur during grading.923924#### Python grading errors925926- `python_grader_server_error_mean`: These errors occur when our system for executing python graders in a remote sandbox experiences system errors. This normally happens due to reasons outside of your control, like networking failures or system outages. If you see a large number of these errors, it is likely that there is a system issue that is causing the errors. You can check the [OpenAI status page](https://status.openai.com/) for more information on any ongoing issues.927- `python_grader_runtime_error_mean`: These errors occur when the python grader itself fails to execute properly. This can happen for a variety of reasons, including bugs in the grading logic, or if the grader is trying to access a variable that doesn't exist in the current context. If you see a large number of these errors, it is likely that there is a bug in your grading logic that needs to be fixed. If a large enough number of these errors occur, the job will fail and we will show you a sampling of tracebacks from the failed graders.928929#### Model grading errors930931- `model_grader_server_error_mean`: These errors occur when we fail to sample from a model grader. This can happen for a variety of reasons, but generally means that either the model grader was misconfigured, that you are attempting to use a model that is not available to your organization, or that there is a system issue that is happening at OpenAI.